Skip to content

Commit 53311be

Browse files
committed
Initial prototype of @rushstack/rush-sdk proxy
1 parent d89fd8c commit 53311be

19 files changed

+211
-20
lines changed

apps/rush-sdk/config/heft.json

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* Defines configuration used by core Heft.
3+
*/
4+
{
5+
"$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json",
6+
7+
"extends": "@rushstack/heft-node-rig/profiles/default/config/heft.json",
8+
"eventActions": [
9+
{
10+
/**
11+
* (Required) The kind of built-in operation that should be performed.
12+
* The "copyFiles" action copies files that match the specified patterns.
13+
*/
14+
"actionKind": "copyFiles",
15+
16+
/**
17+
* (Required) The Heft stage when this action should be performed. Note that heft.json event actions
18+
* are scheduled after any plugin tasks have processed the event. For example, a "compile" event action
19+
* will be performed after the TypeScript compiler has been invoked.
20+
*
21+
* Options: "pre-compile", "compile", "bundle", "post-build"
22+
*/
23+
"heftEvent": "pre-compile",
24+
25+
/**
26+
* (Required) A user-defined tag whose purpose is to allow configs to replace/delete handlers that
27+
* were added by other configs.
28+
*/
29+
"actionId": "copy-rush-lib-dts",
30+
31+
/**
32+
* (Required) An array of copy operations to run perform during the specified Heft event.
33+
*/
34+
"copyOperations": [
35+
{
36+
/**
37+
* (Required) The base folder that files will be copied from, relative to the project root.
38+
* Settings such as "includeGlobs" and "excludeGlobs" will be resolved relative
39+
* to this folder.
40+
* NOTE: Assigning "sourceFolder" does not by itself select any files to be copied.
41+
*/
42+
"sourceFolder": "node_modules/@microsoft/rush-lib/dist/",
43+
44+
/**
45+
* (Required) One or more folders that files will be copied into, relative to the project root.
46+
* If you specify more than one destination folder, Heft will read the input files only once, using
47+
* streams to efficiently write multiple outputs.
48+
*/
49+
"destinationFolders": ["dist"],
50+
51+
/**
52+
* If specified, this option recursively scans all folders under "sourceFolder" and includes any files
53+
* that match the specified extensions. (If "fileExtensions" and "includeGlobs" are both
54+
* specified, their selections are added together.)
55+
*/
56+
// "fileExtensions": [".jpg", ".png"],
57+
58+
/**
59+
* A list of glob patterns that select files to be copied. The paths are resolved relative
60+
* to "sourceFolder".
61+
* Documentation for supported glob syntaxes: https:www.npmjs.com/package/fast-glob
62+
*/
63+
"includeGlobs": ["rush-lib.d.ts"]
64+
65+
/**
66+
* A list of glob patterns that exclude files/folders from being copied. The paths are resolved relative
67+
* to "sourceFolder". These exclusions eliminate items that were selected by the "includeGlobs"
68+
* or "fileExtensions" setting.
69+
*/
70+
// "excludeGlobs": [],
71+
72+
/**
73+
* Normally, when files are selected under a child folder, a corresponding folder will be created in
74+
* the destination folder. Specify flatten=true to discard the source path and copy all matching files
75+
* to the same folder. If two files have the same name an error will be reported.
76+
* The default value is false.
77+
*/
78+
// "flatten": false,
79+
80+
/**
81+
* If true, filesystem hard links will be created instead of copying the file. Depending on the
82+
* operating system, this may be faster. (But note that it may cause unexpected behavior if a tool
83+
* modifies the link.) The default value is false.
84+
*/
85+
// "hardlink": false
86+
}
87+
]
88+
}
89+
]
90+
}

apps/rush-sdk/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
"engineStrict": true,
1414
"homepage": "https://rushjs.io",
1515
"main": "lib/index.js",
16-
"typings": "dist/rush-sdk.d.ts",
16+
"typings": "dist/rush-lib.d.ts",
1717
"scripts": {
1818
"build": "heft test --clean"
1919
},
2020
"license": "MIT",
2121
"dependencies": {
2222
"@rushstack/node-core-library": "workspace:*",
23-
"node-fetch": "2.6.2",
23+
"@types/node-fetch": "1.6.9",
2424
"tapable": "2.2.1"
2525
},
2626
"devDependencies": {

apps/rush-sdk/src/index.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
4+
import * as path from 'path';
5+
import { Import, IPackageJson, PackageJsonLookup } from '@rushstack/node-core-library';
6+
7+
// eslint-disable-next-line
8+
let rushLibModule: any = (global as any).___rush___rushLibModule;
9+
10+
if (rushLibModule === undefined) {
11+
const importingPath: string | undefined = module?.parent?.filename;
12+
if (importingPath !== undefined) {
13+
const callerPackageFolder: string | undefined =
14+
PackageJsonLookup.instance.tryGetPackageFolderFor(importingPath);
15+
16+
if (callerPackageFolder !== undefined) {
17+
const callerPackageJson: IPackageJson = require(path.join(callerPackageFolder, 'package.json'));
18+
19+
const RUSH_LIB_NAME: string = '@microsoft/rush-lib';
20+
21+
// Does the caller properly declare a dependency on rush-lib?
22+
if (
23+
(callerPackageJson.dependencies && callerPackageJson.dependencies[RUSH_LIB_NAME] !== undefined) ||
24+
(callerPackageJson.devDependencies &&
25+
callerPackageJson.devDependencies[RUSH_LIB_NAME] !== undefined) ||
26+
(callerPackageJson.peerDependencies &&
27+
callerPackageJson.peerDependencies[RUSH_LIB_NAME] !== undefined)
28+
) {
29+
// Try to resolve rush-lib from the caller's folder
30+
try {
31+
const rushLibModulePath: string = Import.resolveModule({
32+
modulePath: '@microsoft/rush-lib',
33+
baseFolderPath: callerPackageFolder
34+
});
35+
36+
rushLibModule = require(rushLibModulePath);
37+
} catch (error) {
38+
// If we fail to resolve it, ignore the error
39+
}
40+
}
41+
}
42+
}
43+
}
44+
45+
if (rushLibModule === undefined) {
46+
throw new Error('The "@rushstack/rush-sdk" package context has not been initialized.');
47+
}
48+
49+
// Based on TypeScript's __exportStar()
50+
for (const property in rushLibModule) {
51+
if (property !== 'default' && !exports.hasOwnProperty(property)) {
52+
// Based on TypeScript's __createBinding()
53+
Object.defineProperty(exports, property, {
54+
enumerable: true,
55+
get: function () {
56+
return rushLibModule[property];
57+
}
58+
});
59+
}
60+
}

common/config/rush/pnpm-lock.yaml

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/config/rush/repo-state.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
22
{
3-
"pnpmShrinkwrapHash": "39a04ceec39f9f8f00b7f3589d45d93165eb0165",
3+
"pnpmShrinkwrapHash": "017e3c607e53ecbc686205b49a8eaafb889cea4e",
44
"preferredVersionsHash": "fe0ea762c60633ea39d8abd6f7e0791352654f89"
55
}

common/reviews/api/rush-amazon-s3-build-cache-plugin.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
55
```ts
66

7-
import type { IRushPlugin } from '@microsoft/rush-lib';
8-
import type { RushConfiguration } from '@microsoft/rush-lib';
9-
import type { RushSession } from '@microsoft/rush-lib';
7+
import type { IRushPlugin } from '@rushstack/rush-sdk';
8+
import type { RushConfiguration } from '@rushstack/rush-sdk';
9+
import type { RushSession } from '@rushstack/rush-sdk';
1010

1111
// @public (undocumented)
1212
class RushAmazonS3BuildCachePlugin implements IRushPlugin {

common/reviews/api/rush-azure-storage-build-cache-plugin.api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
55
```ts
66

7-
import type { IRushPlugin } from '@microsoft/rush-lib';
8-
import type { RushConfiguration } from '@microsoft/rush-lib';
9-
import type { RushSession } from '@microsoft/rush-lib';
7+
import type { IRushPlugin } from '@rushstack/rush-sdk';
8+
import type { RushConfiguration } from '@rushstack/rush-sdk';
9+
import type { RushSession } from '@rushstack/rush-sdk';
1010

1111
// @public (undocumented)
1212
class RushAzureStorageBuildCachePlugin implements IRushPlugin {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Debug Jest tests",
11+
"program": "${workspaceFolder}/node_modules/@rushstack/heft/lib/start.js",
12+
"cwd": "${workspaceFolder}",
13+
"args": ["--debug", "test", "--clean"],
14+
"console": "integratedTerminal",
15+
"sourceMaps": true
16+
}
17+
]
18+
}

rush-plugins/rush-amazon-s3-build-cache-plugin/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"node-fetch": "2.6.2"
2121
},
2222
"devDependencies": {
23+
"@microsoft/rush-lib": "workspace:*",
2324
"@rushstack/eslint-config": "workspace:*",
2425
"@rushstack/heft": "workspace:*",
2526
"@rushstack/heft-node-rig": "workspace:*",

rush-plugins/rush-amazon-s3-build-cache-plugin/src/AmazonS3BuildCacheProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
ICredentialCacheEntry,
88
ICredentialCache,
99
RushSession
10-
} from '@microsoft/rush-lib';
10+
} from '@rushstack/rush-sdk';
1111

1212
import { AmazonS3Client, IAmazonS3Credentials } from './AmazonS3Client';
1313

0 commit comments

Comments
 (0)