@backstage/cli 0.36.0-next.2 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +95 -0
- package/config/eslint-factory.js +1 -0
- package/config/getJestEnvironment.js +7 -29
- package/config/jest-environment-jsdom/index.js +9 -43
- package/config/jest.js +7 -401
- package/config/jestCacheResultProcessor.cjs +10 -6
- package/config/jestCachingModuleLoader.js +11 -19
- package/config/jestFileTransform.js +11 -28
- package/config/jestRejectNetworkRequests.js +10 -53
- package/config/jestSucraseTransform.js +10 -70
- package/config/jestSwcTransform.js +10 -27
- package/config/jestYamlTransform.js +11 -24
- package/config/nodeTransform.cjs +10 -70
- package/config/nodeTransformHooks.mjs +4 -278
- package/config/webpack-public-path.js +10 -14
- package/dist/cli-internal/src/InternalCliModule.cjs.js +11 -0
- package/dist/cli-internal/src/InternalCommandNode.cjs.js +25 -0
- package/dist/cli-internal/src/knownPluginPackages.cjs.js +40 -0
- package/dist/index.cjs.js +21 -11
- package/dist/wiring/CliInitializer.cjs.js +61 -30
- package/dist/wiring/CommandGraph.cjs.js +81 -23
- package/dist/wiring/discoverCliModules.cjs.js +44 -0
- package/package.json +27 -160
- package/dist/modules/auth/commands/list.cjs.js +0 -23
- package/dist/modules/auth/commands/login.cjs.js +0 -316
- package/dist/modules/auth/commands/logout.cjs.js +0 -55
- package/dist/modules/auth/commands/printToken.cjs.js +0 -41
- package/dist/modules/auth/commands/select.cjs.js +0 -32
- package/dist/modules/auth/commands/show.cjs.js +0 -59
- package/dist/modules/auth/index.cjs.js +0 -44
- package/dist/modules/auth/lib/auth.cjs.js +0 -60
- package/dist/modules/auth/lib/http.cjs.js +0 -26
- package/dist/modules/auth/lib/localServer.cjs.js +0 -80
- package/dist/modules/auth/lib/pkce.cjs.js +0 -23
- package/dist/modules/auth/lib/prompt.cjs.js +0 -44
- package/dist/modules/auth/lib/secretStore.cjs.js +0 -81
- package/dist/modules/auth/lib/storage.cjs.js +0 -152
- package/dist/modules/build/commands/buildWorkspace.cjs.js +0 -53
- package/dist/modules/build/commands/package/build/command.cjs.js +0 -136
- package/dist/modules/build/commands/package/build/index.cjs.js +0 -10
- package/dist/modules/build/commands/package/clean.cjs.js +0 -21
- package/dist/modules/build/commands/package/postpack.cjs.js +0 -15
- package/dist/modules/build/commands/package/prepack.cjs.js +0 -29
- package/dist/modules/build/commands/package/start/command.cjs.js +0 -80
- package/dist/modules/build/commands/package/start/index.cjs.js +0 -10
- package/dist/modules/build/commands/package/start/resolveLinkedWorkspace.cjs.js +0 -34
- package/dist/modules/build/commands/package/start/startBackend.cjs.js +0 -46
- package/dist/modules/build/commands/package/start/startFrontend.cjs.js +0 -50
- package/dist/modules/build/commands/package/start/startPackage.cjs.js +0 -53
- package/dist/modules/build/commands/repo/build.cjs.js +0 -149
- package/dist/modules/build/commands/repo/clean.cjs.js +0 -41
- package/dist/modules/build/commands/repo/start.cjs.js +0 -199
- package/dist/modules/build/index.cjs.js +0 -68
- package/dist/modules/build/lib/buildBackend.cjs.js +0 -81
- package/dist/modules/build/lib/buildFrontend.cjs.js +0 -50
- package/dist/modules/build/lib/builder/config.cjs.js +0 -257
- package/dist/modules/build/lib/builder/packager.cjs.js +0 -131
- package/dist/modules/build/lib/builder/plugins.cjs.js +0 -125
- package/dist/modules/build/lib/builder/types.cjs.js +0 -10
- package/dist/modules/build/lib/bundler/ConfigInjectingHtmlWebpackPlugin.cjs.js +0 -43
- package/dist/modules/build/lib/bundler/bundle.cjs.js +0 -189
- package/dist/modules/build/lib/bundler/config.cjs.js +0 -308
- package/dist/modules/build/lib/bundler/hasReactDomClient.cjs.js +0 -17
- package/dist/modules/build/lib/bundler/linkWorkspaces.cjs.js +0 -34
- package/dist/modules/build/lib/bundler/moduleFederation.cjs.js +0 -135
- package/dist/modules/build/lib/bundler/optimization.cjs.js +0 -68
- package/dist/modules/build/lib/bundler/packageDetection.cjs.js +0 -124
- package/dist/modules/build/lib/bundler/paths.cjs.js +0 -62
- package/dist/modules/build/lib/bundler/server.cjs.js +0 -231
- package/dist/modules/build/lib/bundler/transforms.cjs.js +0 -145
- package/dist/modules/build/lib/config.cjs.js +0 -94
- package/dist/modules/build/lib/entryPoints.cjs.js +0 -49
- package/dist/modules/build/lib/ipc/IpcServer.cjs.js +0 -60
- package/dist/modules/build/lib/ipc/ServerDataStore.cjs.js +0 -36
- package/dist/modules/build/lib/optionsParser.cjs.js +0 -22
- package/dist/modules/build/lib/packager/createDistWorkspace.cjs.js +0 -235
- package/dist/modules/build/lib/packager/productionPack.cjs.js +0 -160
- package/dist/modules/build/lib/publishing.cjs.js +0 -40
- package/dist/modules/build/lib/role.cjs.js +0 -24
- package/dist/modules/build/lib/runner/runBackend.cjs.js +0 -136
- package/dist/modules/build/lib/typeDistProject.cjs.js +0 -89
- package/dist/modules/build/lib/urls.cjs.js +0 -13
- package/dist/modules/config/commands/docs.cjs.js +0 -63
- package/dist/modules/config/commands/print.cjs.js +0 -81
- package/dist/modules/config/commands/schema.cjs.js +0 -56
- package/dist/modules/config/commands/validate.cjs.js +0 -50
- package/dist/modules/config/index.cjs.js +0 -51
- package/dist/modules/config/lib/config.cjs.js +0 -94
- package/dist/modules/create-github-app/commands/create-github-app/GithubCreateAppServer.cjs.js +0 -127
- package/dist/modules/create-github-app/commands/create-github-app/index.cjs.js +0 -126
- package/dist/modules/create-github-app/index.cjs.js +0 -19
- package/dist/modules/info/commands/info.cjs.js +0 -182
- package/dist/modules/info/index.cjs.js +0 -19
- package/dist/modules/lint/commands/package/lint.cjs.js +0 -78
- package/dist/modules/lint/commands/repo/lint.cjs.js +0 -282
- package/dist/modules/lint/index.cjs.js +0 -24
- package/dist/modules/lint/lib/optionsParser.cjs.js +0 -22
- package/dist/modules/maintenance/commands/repo/fix.cjs.js +0 -426
- package/dist/modules/maintenance/commands/repo/list-deprecations.cjs.js +0 -90
- package/dist/modules/maintenance/index.cjs.js +0 -24
- package/dist/modules/migrate/commands/packageExports.cjs.js +0 -15
- package/dist/modules/migrate/commands/packageLintConfigs.cjs.js +0 -77
- package/dist/modules/migrate/commands/packageRole.cjs.js +0 -57
- package/dist/modules/migrate/commands/packageScripts.cjs.js +0 -87
- package/dist/modules/migrate/commands/reactRouterDeps.cjs.js +0 -51
- package/dist/modules/migrate/commands/versions/bump.cjs.js +0 -403
- package/dist/modules/migrate/commands/versions/migrate.cjs.js +0 -133
- package/dist/modules/migrate/index.cjs.js +0 -59
- package/dist/modules/migrate/lib/utils.cjs.js +0 -44
- package/dist/modules/migrate/lib/versioning/packages.cjs.js +0 -71
- package/dist/modules/migrate/lib/versioning/yarn.cjs.js +0 -28
- package/dist/modules/new/commands/new.cjs.js +0 -115
- package/dist/modules/new/index.cjs.js +0 -40
- package/dist/modules/new/lib/codeowners/codeowners.cjs.js +0 -92
- package/dist/modules/new/lib/createNewPackage.cjs.js +0 -32
- package/dist/modules/new/lib/defaultTemplates.cjs.js +0 -17
- package/dist/modules/new/lib/execution/PortableTemplater.cjs.js +0 -89
- package/dist/modules/new/lib/execution/executePortableTemplate.cjs.js +0 -66
- package/dist/modules/new/lib/execution/installNewPackage.cjs.js +0 -127
- package/dist/modules/new/lib/execution/writeTemplateContents.cjs.js +0 -116
- package/dist/modules/new/lib/preparation/collectPortableTemplateInput.cjs.js +0 -157
- package/dist/modules/new/lib/preparation/loadPortableTemplate.cjs.js +0 -81
- package/dist/modules/new/lib/preparation/loadPortableTemplateConfig.cjs.js +0 -132
- package/dist/modules/new/lib/preparation/resolvePackageParams.cjs.js +0 -40
- package/dist/modules/new/lib/preparation/selectTemplateInteractively.cjs.js +0 -38
- package/dist/modules/new/lib/tasks.cjs.js +0 -51
- package/dist/modules/new/lib/types.cjs.js +0 -19
- package/dist/modules/new/lib/version.cjs.js +0 -91
- package/dist/modules/test/commands/package/test.cjs.js +0 -59
- package/dist/modules/test/commands/repo/test.cjs.js +0 -299
- package/dist/modules/test/index.cjs.js +0 -24
- package/dist/modules/translations/commands/export.cjs.js +0 -128
- package/dist/modules/translations/commands/import.cjs.js +0 -165
- package/dist/modules/translations/index.cjs.js +0 -24
- package/dist/modules/translations/lib/discoverPackages.cjs.js +0 -121
- package/dist/modules/translations/lib/extractTranslations.cjs.js +0 -71
- package/dist/modules/translations/lib/messageFilePath.cjs.js +0 -43
- package/dist/packages/backend-defaults/package.json.cjs.js +0 -6
- package/dist/packages/backend-plugin-api/package.json.cjs.js +0 -6
- package/dist/packages/backend-test-utils/package.json.cjs.js +0 -6
- package/dist/packages/catalog-client/package.json.cjs.js +0 -6
- package/dist/packages/cli/package.json.cjs.js +0 -159
- package/dist/packages/config/package.json.cjs.js +0 -6
- package/dist/packages/core-app-api/package.json.cjs.js +0 -6
- package/dist/packages/core-components/package.json.cjs.js +0 -6
- package/dist/packages/core-plugin-api/package.json.cjs.js +0 -6
- package/dist/packages/dev-utils/package.json.cjs.js +0 -6
- package/dist/packages/errors/package.json.cjs.js +0 -6
- package/dist/packages/frontend-defaults/package.json.cjs.js +0 -6
- package/dist/packages/frontend-plugin-api/package.json.cjs.js +0 -6
- package/dist/packages/frontend-plugin-api/src/routing/describeParentCallSite.cjs.js +0 -26
- package/dist/packages/frontend-test-utils/package.json.cjs.js +0 -6
- package/dist/packages/test-utils/package.json.cjs.js +0 -6
- package/dist/packages/theme/package.json.cjs.js +0 -6
- package/dist/packages/types/package.json.cjs.js +0 -6
- package/dist/plugins/auth-backend/package.json.cjs.js +0 -6
- package/dist/plugins/auth-backend-module-guest-provider/package.json.cjs.js +0 -6
- package/dist/plugins/catalog-node/package.json.cjs.js +0 -6
- package/dist/plugins/scaffolder-node/package.json.cjs.js +0 -6
- package/dist/plugins/scaffolder-node-test-utils/package.json.cjs.js +0 -6
- package/dist/wiring/CommandRegistry.cjs.js +0 -14
- package/dist/wiring/factory.cjs.js +0 -15
- package/dist/wiring/types.cjs.js +0 -11
- package/templates/backend-plugin/.eslintrc.js.hbs +0 -1
- package/templates/backend-plugin/README.md.hbs +0 -28
- package/templates/backend-plugin/dev/index.ts.hbs +0 -60
- package/templates/backend-plugin/package.json.hbs +0 -44
- package/templates/backend-plugin/portable-template.yaml +0 -5
- package/templates/backend-plugin/src/index.ts.hbs +0 -1
- package/templates/backend-plugin/src/plugin.test.ts.hbs +0 -129
- package/templates/backend-plugin/src/plugin.ts.hbs +0 -32
- package/templates/backend-plugin/src/router.test.ts +0 -67
- package/templates/backend-plugin/src/router.ts +0 -51
- package/templates/backend-plugin/src/services/TodoListService.ts +0 -155
- package/templates/backend-plugin/src/setupTests.ts +0 -1
- package/templates/backend-plugin-module/.eslintrc.js.hbs +0 -1
- package/templates/backend-plugin-module/README.md.hbs +0 -5
- package/templates/backend-plugin-module/package.json.hbs +0 -34
- package/templates/backend-plugin-module/portable-template.yaml +0 -5
- package/templates/backend-plugin-module/src/index.ts.hbs +0 -8
- package/templates/backend-plugin-module/src/module.ts.hbs +0 -17
- package/templates/catalog-provider-module/.eslintrc.js.hbs +0 -1
- package/templates/catalog-provider-module/README.md.hbs +0 -5
- package/templates/catalog-provider-module/config.d.ts.hbs +0 -34
- package/templates/catalog-provider-module/package.json.hbs +0 -36
- package/templates/catalog-provider-module/portable-template.yaml +0 -9
- package/templates/catalog-provider-module/src/index.ts.hbs +0 -8
- package/templates/catalog-provider-module/src/module.ts.hbs +0 -29
- package/templates/catalog-provider-module/src/provider/readProviderConfigs.ts.hbs +0 -78
- package/templates/catalog-provider-module/src/provider/{{providerClass}}.test.ts.hbs +0 -18
- package/templates/catalog-provider-module/src/provider/{{providerClass}}.ts.hbs +0 -109
- package/templates/frontend-plugin/.eslintrc.js.hbs +0 -1
- package/templates/frontend-plugin/README.md.hbs +0 -13
- package/templates/frontend-plugin/dev/index.tsx.hbs +0 -11
- package/templates/frontend-plugin/package.json.hbs +0 -54
- package/templates/frontend-plugin/portable-template.yaml +0 -6
- package/templates/frontend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +0 -28
- package/templates/frontend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs +0 -37
- package/templates/frontend-plugin/src/components/ExampleComponent/index.ts +0 -1
- package/templates/frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +0 -19
- package/templates/frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +0 -308
- package/templates/frontend-plugin/src/components/ExampleFetchComponent/index.ts +0 -1
- package/templates/frontend-plugin/src/index.ts.hbs +0 -1
- package/templates/frontend-plugin/src/plugin.test.ts.hbs +0 -7
- package/templates/frontend-plugin/src/plugin.ts.hbs +0 -22
- package/templates/frontend-plugin/src/routes.ts.hbs +0 -5
- package/templates/frontend-plugin/src/setupTests.ts +0 -1
- package/templates/new-frontend-plugin/.eslintrc.js.hbs +0 -1
- package/templates/new-frontend-plugin/README.md.hbs +0 -20
- package/templates/new-frontend-plugin/dev/index.tsx +0 -10
- package/templates/new-frontend-plugin/package.json.hbs +0 -49
- package/templates/new-frontend-plugin/portable-template.yaml +0 -5
- package/templates/new-frontend-plugin/src/components/ExampleComponent/ExampleComponent.test.tsx.hbs +0 -28
- package/templates/new-frontend-plugin/src/components/ExampleComponent/ExampleComponent.tsx.hbs +0 -37
- package/templates/new-frontend-plugin/src/components/ExampleComponent/index.ts +0 -1
- package/templates/new-frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.test.tsx.hbs +0 -19
- package/templates/new-frontend-plugin/src/components/ExampleFetchComponent/ExampleFetchComponent.tsx.hbs +0 -308
- package/templates/new-frontend-plugin/src/components/ExampleFetchComponent/index.ts +0 -1
- package/templates/new-frontend-plugin/src/index.ts.hbs +0 -1
- package/templates/new-frontend-plugin/src/plugin.test.ts.hbs +0 -7
- package/templates/new-frontend-plugin/src/plugin.tsx.hbs +0 -25
- package/templates/new-frontend-plugin/src/routes.ts +0 -3
- package/templates/new-frontend-plugin/src/setupTests.ts +0 -1
- package/templates/new-frontend-plugin-module/.eslintrc.js.hbs +0 -1
- package/templates/new-frontend-plugin-module/README.md.hbs +0 -5
- package/templates/new-frontend-plugin-module/package.json.hbs +0 -35
- package/templates/new-frontend-plugin-module/portable-template.yaml +0 -5
- package/templates/new-frontend-plugin-module/src/index.ts.hbs +0 -1
- package/templates/new-frontend-plugin-module/src/module.tsx.hbs +0 -8
- package/templates/new-frontend-plugin-module/src/setupTests.ts +0 -1
- package/templates/node-library/.eslintrc.js.hbs +0 -1
- package/templates/node-library/README.md.hbs +0 -12
- package/templates/node-library/package.json.hbs +0 -29
- package/templates/node-library/portable-template.yaml +0 -3
- package/templates/node-library/src/index.ts.hbs +0 -1
- package/templates/node-library/src/setupTests.ts +0 -1
- package/templates/plugin-common-library/.eslintrc.js.hbs +0 -1
- package/templates/plugin-common-library/README.md.hbs +0 -5
- package/templates/plugin-common-library/package.json.hbs +0 -31
- package/templates/plugin-common-library/portable-template.yaml +0 -3
- package/templates/plugin-common-library/src/index.ts.hbs +0 -19
- package/templates/plugin-common-library/src/setupTests.ts +0 -1
- package/templates/plugin-node-library/.eslintrc.js.hbs +0 -1
- package/templates/plugin-node-library/README.md.hbs +0 -5
- package/templates/plugin-node-library/package.json.hbs +0 -30
- package/templates/plugin-node-library/portable-template.yaml +0 -3
- package/templates/plugin-node-library/src/index.ts.hbs +0 -18
- package/templates/plugin-node-library/src/setupTests.ts +0 -1
- package/templates/plugin-web-library/.eslintrc.js.hbs +0 -1
- package/templates/plugin-web-library/README.md.hbs +0 -5
- package/templates/plugin-web-library/package.json.hbs +0 -42
- package/templates/plugin-web-library/portable-template.yaml +0 -3
- package/templates/plugin-web-library/src/components/ExampleComponent/ExampleComponent.test.tsx +0 -17
- package/templates/plugin-web-library/src/components/ExampleComponent/ExampleComponent.tsx +0 -28
- package/templates/plugin-web-library/src/components/ExampleComponent/index.ts +0 -2
- package/templates/plugin-web-library/src/components/index.ts +0 -5
- package/templates/plugin-web-library/src/hooks/index.ts +0 -5
- package/templates/plugin-web-library/src/hooks/useExample/index.ts +0 -1
- package/templates/plugin-web-library/src/hooks/useExample/useExample.ts +0 -15
- package/templates/plugin-web-library/src/index.ts.hbs +0 -12
- package/templates/plugin-web-library/src/setupTests.ts +0 -1
- package/templates/scaffolder-backend-module/.eslintrc.js.hbs +0 -1
- package/templates/scaffolder-backend-module/README.md.hbs +0 -5
- package/templates/scaffolder-backend-module/package.json.hbs +0 -36
- package/templates/scaffolder-backend-module/portable-template.yaml +0 -6
- package/templates/scaffolder-backend-module/src/actions/example.test.ts +0 -24
- package/templates/scaffolder-backend-module/src/actions/example.ts +0 -39
- package/templates/scaffolder-backend-module/src/index.ts.hbs +0 -8
- package/templates/scaffolder-backend-module/src/module.ts +0 -21
- package/templates/web-library/.eslintrc.js.hbs +0 -1
- package/templates/web-library/README.md.hbs +0 -12
- package/templates/web-library/package.json.hbs +0 -30
- package/templates/web-library/portable-template.yaml +0 -3
- package/templates/web-library/src/index.ts.hbs +0 -1
- package/templates/web-library/src/setupTests.ts +0 -1
- /package/dist/{packages/opaque-internal → opaque-internal}/src/OpaqueType.cjs.js +0 -0
|
@@ -14,31 +14,14 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
__esModule: true,
|
|
29
|
-
default: props => React.createElement(SvgIcon, props, {
|
|
30
|
-
$$typeof: Symbol.for('react.element'),
|
|
31
|
-
type: 'svg',
|
|
32
|
-
ref: ref,
|
|
33
|
-
key: null,
|
|
34
|
-
props: Object.assign({}, props, {
|
|
35
|
-
children: ${assetFilename}
|
|
36
|
-
})
|
|
37
|
-
})
|
|
38
|
-
};`,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return { code: `module.exports = ${assetFilename};` };
|
|
43
|
-
},
|
|
44
|
-
};
|
|
17
|
+
try {
|
|
18
|
+
module.exports = require('@backstage/cli-module-test-jest/config/jestFileTransform');
|
|
19
|
+
} catch (e) {
|
|
20
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
|
21
|
+
throw new Error(
|
|
22
|
+
'@backstage/cli-module-test-jest is required to use the jest file transform. ' +
|
|
23
|
+
'Please install it as a dependency.',
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
throw e;
|
|
27
|
+
}
|
|
@@ -14,57 +14,14 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
http.globalAgent = new http.Agent({
|
|
28
|
-
lookup() {
|
|
29
|
-
throw new Error(errorMessage);
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
https.globalAgent = new https.Agent({
|
|
34
|
-
lookup() {
|
|
35
|
-
throw new Error(errorMessage);
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const BLOCKING_FETCH_SYMBOL = Symbol.for(
|
|
40
|
-
'backstage.jestRejectNetworkRequests.blockingFetch',
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
if (global.fetch) {
|
|
44
|
-
const blockingFetch = async (input, init) => {
|
|
45
|
-
// If global.fetch still has our marker, block the request
|
|
46
|
-
if (global.fetch[BLOCKING_FETCH_SYMBOL]) {
|
|
47
|
-
throw new Error(errorMessage);
|
|
48
|
-
}
|
|
49
|
-
// MSW (or something else) wrapped us - pass through
|
|
50
|
-
return origFetch(input, init);
|
|
51
|
-
};
|
|
52
|
-
blockingFetch[BLOCKING_FETCH_SYMBOL] = true;
|
|
53
|
-
global.fetch = blockingFetch;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (global.XMLHttpRequest) {
|
|
57
|
-
global.XMLHttpRequest = class {
|
|
58
|
-
constructor() {
|
|
59
|
-
throw new Error(errorMessage);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
17
|
+
try {
|
|
18
|
+
module.exports = require('@backstage/cli-module-test-jest/config/jestRejectNetworkRequests');
|
|
19
|
+
} catch (e) {
|
|
20
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
|
21
|
+
throw new Error(
|
|
22
|
+
'@backstage/cli-module-test-jest is required to use the jest network request rejection. ' +
|
|
23
|
+
'Please install it as a dependency.',
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
throw e;
|
|
62
27
|
}
|
|
63
|
-
|
|
64
|
-
// Reset overrides after each suite to make sure we don't pollute the test environment
|
|
65
|
-
afterAll(() => {
|
|
66
|
-
http.globalAgent = origHttpAgent;
|
|
67
|
-
https.globalAgent = origHttpsAgent;
|
|
68
|
-
global.fetch = origFetch;
|
|
69
|
-
global.XMLHttpRequest = origXMLHttpRequest;
|
|
70
|
-
});
|
|
@@ -14,74 +14,14 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (filePath.endsWith('.esm.js')) {
|
|
28
|
-
transforms = ['imports'];
|
|
29
|
-
} else if (filePath.endsWith('.js')) {
|
|
30
|
-
// This is a very rough filter to avoid transforming things that we quickly
|
|
31
|
-
// can be sure are definitely not ESM modules.
|
|
32
|
-
if (ESM_REGEX.test(source)) {
|
|
33
|
-
transforms = ['imports', 'jsx']; // JSX within .js is currently allowed
|
|
34
|
-
}
|
|
35
|
-
} else if (filePath.endsWith('.jsx')) {
|
|
36
|
-
transforms = ['jsx', 'imports'];
|
|
37
|
-
} else if (filePath.endsWith('.ts')) {
|
|
38
|
-
transforms = ['typescript', 'imports'];
|
|
39
|
-
} else if (filePath.endsWith('.tsx')) {
|
|
40
|
-
transforms = ['typescript', 'jsx', 'imports'];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Only apply the jest transform to the test files themselves
|
|
44
|
-
if (transforms && filePath.includes('.test.')) {
|
|
45
|
-
transforms.push('jest');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (transforms) {
|
|
49
|
-
const { code, sourceMap: map } = transform(source, {
|
|
50
|
-
transforms,
|
|
51
|
-
filePath,
|
|
52
|
-
disableESTransforms: true,
|
|
53
|
-
sourceMapOptions: {
|
|
54
|
-
compiledFilename: filePath,
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
if (config.enableSourceMaps) {
|
|
58
|
-
const b64 = Buffer.from(JSON.stringify(map), 'utf8').toString('base64');
|
|
59
|
-
const suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${b64}`;
|
|
60
|
-
// Include both inline and object source maps, as inline source maps are
|
|
61
|
-
// needed for support of some editor integrations.
|
|
62
|
-
return { code: `${code}\n${suffix}`, map };
|
|
63
|
-
}
|
|
64
|
-
// We only return the `map` result if source maps are enabled, as they
|
|
65
|
-
// have a negative impact on the coverage accuracy.
|
|
66
|
-
return { code };
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return { code: source };
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const getCacheKey = sourceText => {
|
|
73
|
-
return createHash('sha256')
|
|
74
|
-
.update(sourceText)
|
|
75
|
-
.update(Buffer.alloc(1))
|
|
76
|
-
.update(sucrasePkg.version)
|
|
77
|
-
.update(Buffer.alloc(1))
|
|
78
|
-
.update(JSON.stringify(config))
|
|
79
|
-
.update(Buffer.alloc(1))
|
|
80
|
-
.update('1') // increment whenever the transform logic in this file changes
|
|
81
|
-
.digest('hex');
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
return { process, getCacheKey };
|
|
17
|
+
try {
|
|
18
|
+
module.exports = require('@backstage/cli-module-test-jest/config/jestSucraseTransform');
|
|
19
|
+
} catch (e) {
|
|
20
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
|
21
|
+
throw new Error(
|
|
22
|
+
'@backstage/cli-module-test-jest is required to use the jest Sucrase transform. ' +
|
|
23
|
+
'Please install it as a dependency.',
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
throw e;
|
|
85
27
|
}
|
|
86
|
-
|
|
87
|
-
module.exports = { createTransformer };
|
|
@@ -13,32 +13,15 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
const { createTransformer: createSwcTransformer } = require('@swc/jest');
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return { code: source };
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Skip transformation of .mjs files, they should only be used if ESM support is available
|
|
32
|
-
if (jestOptions.supportsStaticESM && filePath.endsWith('.mjs')) {
|
|
33
|
-
return { code: source };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return swcTransformer.process(source, filePath, jestOptions);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const getCacheKey = swcTransformer.getCacheKey;
|
|
40
|
-
|
|
41
|
-
return { process, getCacheKey };
|
|
17
|
+
try {
|
|
18
|
+
module.exports = require('@backstage/cli-module-test-jest/config/jestSwcTransform');
|
|
19
|
+
} catch (e) {
|
|
20
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
|
21
|
+
throw new Error(
|
|
22
|
+
'@backstage/cli-module-test-jest is required to use the jest SWC transform. ' +
|
|
23
|
+
'Please install it as a dependency.',
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
throw e;
|
|
42
27
|
}
|
|
43
|
-
|
|
44
|
-
module.exports = { createTransformer };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2020 The Backstage Authors
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -14,27 +14,14 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return crypto
|
|
28
|
-
.createHash('sha256')
|
|
29
|
-
.update(sourceText)
|
|
30
|
-
.update(Buffer.alloc(1))
|
|
31
|
-
.update(JSON.stringify(config))
|
|
32
|
-
.update(Buffer.alloc(1))
|
|
33
|
-
.update('1') // increment whenever the transform logic in this file changes
|
|
34
|
-
.digest('hex');
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return { process, getCacheKey };
|
|
17
|
+
try {
|
|
18
|
+
module.exports = require('@backstage/cli-module-test-jest/config/jestYamlTransform');
|
|
19
|
+
} catch (e) {
|
|
20
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
|
21
|
+
throw new Error(
|
|
22
|
+
'@backstage/cli-module-test-jest is required to use the jest YAML transform. ' +
|
|
23
|
+
'Please install it as a dependency.',
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
throw e;
|
|
38
27
|
}
|
|
39
|
-
|
|
40
|
-
module.exports = { createTransformer };
|
package/config/nodeTransform.cjs
CHANGED
|
@@ -14,74 +14,14 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const { packages: linkedPackages, root: linkedRoot } = getPackagesSync(
|
|
28
|
-
process.env.BACKSTAGE_CLI_LINKED_WORKSPACE,
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
// Matches all packages in the linked workspaces, as well as sub-path exports from them
|
|
32
|
-
const replacementRegex = new RegExp(
|
|
33
|
-
`^(?:${linkedPackages
|
|
34
|
-
.map(pkg => pkg.packageJson.name)
|
|
35
|
-
.join('|')})(?:/.*)?$`,
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const origLoad = Module._load;
|
|
39
|
-
Module._load = function requireHook(request, parent) {
|
|
40
|
-
if (!replacementRegex.test(request)) {
|
|
41
|
-
return origLoad.call(this, request, parent);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// The package import that we're overriding will always existing in the root
|
|
45
|
-
// node_modules of the linked workspace, so it's enough to override the
|
|
46
|
-
// parent paths with that single entry
|
|
47
|
-
return origLoad.call(this, request, {
|
|
48
|
-
...parent,
|
|
49
|
-
paths: [joinPath(linkedRoot.dir, 'node_modules')],
|
|
50
|
-
});
|
|
51
|
-
};
|
|
17
|
+
try {
|
|
18
|
+
require('@backstage/cli-node/config/nodeTransform.cjs');
|
|
19
|
+
} catch (e) {
|
|
20
|
+
if (e.code === 'MODULE_NOT_FOUND') {
|
|
21
|
+
throw new Error(
|
|
22
|
+
'@backstage/cli-node is required to use the node transform. ' +
|
|
23
|
+
'Please install it as a dependency.',
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
throw e;
|
|
52
27
|
}
|
|
53
|
-
|
|
54
|
-
addHook(
|
|
55
|
-
(code, filename) => {
|
|
56
|
-
const transformed = transformSync(code, {
|
|
57
|
-
filename,
|
|
58
|
-
sourceMaps: 'inline',
|
|
59
|
-
module: {
|
|
60
|
-
type: 'commonjs',
|
|
61
|
-
ignoreDynamic: true,
|
|
62
|
-
},
|
|
63
|
-
jsc: {
|
|
64
|
-
target: 'es2023',
|
|
65
|
-
parser: {
|
|
66
|
-
syntax: 'typescript',
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
process.send?.({ type: 'watch', path: filename });
|
|
71
|
-
return transformed.code;
|
|
72
|
-
},
|
|
73
|
-
{ extensions: ['.ts', '.cts'], ignoreNodeModules: true },
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
addHook(
|
|
77
|
-
(code, filename) => {
|
|
78
|
-
process.send?.({ type: 'watch', path: filename });
|
|
79
|
-
return code;
|
|
80
|
-
},
|
|
81
|
-
{ extensions: ['.js', '.cjs'], ignoreNodeModules: true },
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
// Register module hooks, used by "type": "module" in package.json, .mjs and
|
|
85
|
-
// .mts files, as well as dynamic import(...)s, although dynamic imports will be
|
|
86
|
-
// handled be the CommonJS hooks in this file if what it points to is CommonJS.
|
|
87
|
-
Module.register('./nodeTransformHooks.mjs', pathToFileURL(__filename));
|
|
@@ -14,281 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
import { readFile } from 'node:fs/promises';
|
|
22
|
-
import { existsSync } from 'node:fs';
|
|
23
|
-
|
|
24
|
-
// @ts-check
|
|
25
|
-
|
|
26
|
-
// No explicit file extension, no type in package.json
|
|
27
|
-
const DEFAULT_MODULE_FORMAT = 'commonjs';
|
|
28
|
-
|
|
29
|
-
// Source file extensions to look for when using bundle resolution strategy
|
|
30
|
-
const SRC_EXTS = ['.ts', '.js'];
|
|
31
|
-
const TS_EXTS = ['.ts', '.mts', '.cts'];
|
|
32
|
-
const moduleTypeTable = {
|
|
33
|
-
'.mjs': 'module',
|
|
34
|
-
'.mts': 'module',
|
|
35
|
-
'.cjs': 'commonjs',
|
|
36
|
-
'.cts': 'commonjs',
|
|
37
|
-
'.ts': undefined,
|
|
38
|
-
'.js': undefined,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/** @type {import('module').ResolveHook} */
|
|
42
|
-
export async function resolve(specifier, context, nextResolve) {
|
|
43
|
-
// Built-in modules are handled by the default resolver
|
|
44
|
-
if (isBuiltin(specifier)) {
|
|
45
|
-
return nextResolve(specifier, context);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const ext = extname(specifier);
|
|
49
|
-
|
|
50
|
-
// Unless there's an explicit import attribute, JSON files are loaded with our custom loader that's defined below.
|
|
51
|
-
if (ext === '.json' && !context.importAttributes?.type) {
|
|
52
|
-
const jsonResult = await nextResolve(specifier, context);
|
|
53
|
-
return {
|
|
54
|
-
...jsonResult,
|
|
55
|
-
format: 'commonjs',
|
|
56
|
-
importAttributes: { type: 'json' },
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Anything else with an explicit extension is handled by the default
|
|
61
|
-
// resolver, except that we help determine the module type where needed.
|
|
62
|
-
if (ext !== '') {
|
|
63
|
-
return withDetectedModuleType(await nextResolve(specifier, context));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Other external modules are handled by the default resolver, but again we
|
|
67
|
-
// help determine the module type where needed.
|
|
68
|
-
if (!specifier.startsWith('.')) {
|
|
69
|
-
return withDetectedModuleType(await nextResolve(specifier, context));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// The rest of this function handles the case of resolving imports that do not
|
|
73
|
-
// specify any extension and might point to a directory with an `index.*`
|
|
74
|
-
// file. We resolve those using the same logic as most JS bundlers would, with
|
|
75
|
-
// the addition of checking if there's an explicit module format listed in the
|
|
76
|
-
// closest `package.json` file.
|
|
77
|
-
//
|
|
78
|
-
// We use a bundle resolution strategy in order to keep code consistent across
|
|
79
|
-
// Backstage codebases that contains code both for Web and Node.js, and to
|
|
80
|
-
// support packages with common code that can be used in both environments.
|
|
81
|
-
try {
|
|
82
|
-
// This is expected to throw, but in the event that this module specifier is
|
|
83
|
-
// supported we prefer to use the default resolver.
|
|
84
|
-
return await nextResolve(specifier, context);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
if (error.code === 'ERR_UNSUPPORTED_DIR_IMPORT') {
|
|
87
|
-
const spec = `${specifier}${specifier.endsWith('/') ? '' : '/'}index`;
|
|
88
|
-
const resolved = await resolveWithoutExt(spec, context, nextResolve);
|
|
89
|
-
if (resolved) {
|
|
90
|
-
return withDetectedModuleType(resolved);
|
|
91
|
-
}
|
|
92
|
-
} else if (error.code === 'ERR_MODULE_NOT_FOUND') {
|
|
93
|
-
const resolved = await resolveWithoutExt(specifier, context, nextResolve);
|
|
94
|
-
if (resolved) {
|
|
95
|
-
return withDetectedModuleType(resolved);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Unexpected error or no resolution found
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Populates the `format` field in the resolved object based on the closest `package.json` file.
|
|
106
|
-
*
|
|
107
|
-
* @param {import('module').ResolveFnOutput} resolved
|
|
108
|
-
* @returns {Promise<import('module').ResolveFnOutput>}
|
|
109
|
-
*/
|
|
110
|
-
async function withDetectedModuleType(resolved) {
|
|
111
|
-
// Already has an explicit format
|
|
112
|
-
if (resolved.format) {
|
|
113
|
-
return resolved;
|
|
114
|
-
}
|
|
115
|
-
// Happens in Node.js v22 when there's a package.json without an explicit "type" field. Use the default.
|
|
116
|
-
if (resolved.format === null) {
|
|
117
|
-
return { ...resolved, format: DEFAULT_MODULE_FORMAT };
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const ext = extname(resolved.url);
|
|
121
|
-
|
|
122
|
-
const explicitFormat = moduleTypeTable[ext];
|
|
123
|
-
if (explicitFormat) {
|
|
124
|
-
return {
|
|
125
|
-
...resolved,
|
|
126
|
-
format: explicitFormat,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Under normal circumstances .js files should reliably have a format and so
|
|
131
|
-
// we should only reach this point for .ts files. However, if additional
|
|
132
|
-
// custom loaders are being used the format may not be detected for .js files
|
|
133
|
-
// either. As such we don't restrict the file format at this point.
|
|
134
|
-
|
|
135
|
-
// TODO(Rugvip): Does this need caching? kept it simple for now but worth exploring
|
|
136
|
-
const packageJsonPath = await findPackageJSON(fileURLToPath(resolved.url));
|
|
137
|
-
if (!packageJsonPath) {
|
|
138
|
-
return resolved;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'));
|
|
142
|
-
return {
|
|
143
|
-
...resolved,
|
|
144
|
-
format: packageJson.type ?? DEFAULT_MODULE_FORMAT,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Find the closest package.json file from the given path.
|
|
150
|
-
*
|
|
151
|
-
* TODO(Rugvip): This can be replaced with the Node.js built-in with the same name once it is stable.
|
|
152
|
-
* @param {string} startPath
|
|
153
|
-
* @returns {Promise<string | undefined>}
|
|
154
|
-
*/
|
|
155
|
-
async function findPackageJSON(startPath) {
|
|
156
|
-
let path = startPath;
|
|
157
|
-
|
|
158
|
-
// Some confidence check to avoid infinite loop
|
|
159
|
-
for (let i = 0; i < 1000; i++) {
|
|
160
|
-
const packagePath = resolvePath(path, 'package.json');
|
|
161
|
-
if (existsSync(packagePath)) {
|
|
162
|
-
return packagePath;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const newPath = dirname(path);
|
|
166
|
-
if (newPath === path) {
|
|
167
|
-
return undefined;
|
|
168
|
-
}
|
|
169
|
-
path = newPath;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
throw new Error(
|
|
173
|
-
`Iteration limit reached when searching for package.json at ${startPath}`,
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/** @type {import('module').ResolveHook} */
|
|
178
|
-
async function resolveWithoutExt(specifier, context, nextResolve) {
|
|
179
|
-
for (const tryExt of SRC_EXTS) {
|
|
180
|
-
try {
|
|
181
|
-
const resolved = await nextResolve(specifier + tryExt, {
|
|
182
|
-
...context,
|
|
183
|
-
format: 'commonjs',
|
|
184
|
-
});
|
|
185
|
-
return {
|
|
186
|
-
...resolved,
|
|
187
|
-
format: moduleTypeTable[tryExt] ?? resolved.format,
|
|
188
|
-
};
|
|
189
|
-
} catch {
|
|
190
|
-
/* ignore */
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return undefined;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/** @type {import('module').LoadHook} */
|
|
197
|
-
export async function load(url, context, nextLoad) {
|
|
198
|
-
// Non-file URLs are handled by the default loader
|
|
199
|
-
if (!url.startsWith('file://')) {
|
|
200
|
-
return nextLoad(url, context);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// JSON files loaded as CommonJS are handled by this custom loader, because
|
|
204
|
-
// the default one doesn't work. For JSON loading to work we'd need the
|
|
205
|
-
// synchronous hooks that aren't supported yet, or avoid using the CommonJS
|
|
206
|
-
// compatibility.
|
|
207
|
-
if (
|
|
208
|
-
context.format === 'commonjs' &&
|
|
209
|
-
context.importAttributes?.type === 'json'
|
|
210
|
-
) {
|
|
211
|
-
try {
|
|
212
|
-
// TODO(Rugvip): Make sure this is valid JSON
|
|
213
|
-
const content = await readFile(fileURLToPath(url), 'utf8');
|
|
214
|
-
return {
|
|
215
|
-
source: `module.exports = (${content})`,
|
|
216
|
-
format: 'commonjs',
|
|
217
|
-
shortCircuit: true,
|
|
218
|
-
};
|
|
219
|
-
} catch {
|
|
220
|
-
// Let the default loader generate the error
|
|
221
|
-
return nextLoad(url, context);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const ext = extname(url);
|
|
226
|
-
|
|
227
|
-
// Non-TS files are handled by the default loader
|
|
228
|
-
if (!TS_EXTS.includes(ext)) {
|
|
229
|
-
return nextLoad(url, context);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const format = context.format ?? DEFAULT_MODULE_FORMAT;
|
|
233
|
-
|
|
234
|
-
// We have two choices at this point, we can either transform CommonJS files
|
|
235
|
-
// and return the transformed source code, or let the default loader handle
|
|
236
|
-
// them. If we transform them ourselves we will enter CommonJS compatibility
|
|
237
|
-
// mode in the new module system in Node.js, this effectively means all
|
|
238
|
-
// CommonJS loaded via `require` calls from this point will all be treated as
|
|
239
|
-
// if it was loaded via `import` calls from modules.
|
|
240
|
-
//
|
|
241
|
-
// The CommonJS compatibility layer will try to identify named exports and
|
|
242
|
-
// make them available directly, which is convenient as it avoids things like
|
|
243
|
-
// `import(...).then(m => m.default.foo)`, allowing you to instead write
|
|
244
|
-
// `import(...).then(m => m.foo)`. The compatibility layer doesn't always work
|
|
245
|
-
// all that well though, and can lead to module loading issues in many cases,
|
|
246
|
-
// especially for older code.
|
|
247
|
-
|
|
248
|
-
// This `if` block opts-out of using CommonJS compatibility mode by default,
|
|
249
|
-
// and instead leaves it to our existing loader to transform CommonJS. We do
|
|
250
|
-
// however use compatibility mode for the more explicit .cts file extension,
|
|
251
|
-
// allows for a way to opt-in to the new behavior.
|
|
252
|
-
//
|
|
253
|
-
// TODO(Rugvip): Once the synchronous hooks API is available for us to use, we might be able to adopt that instead
|
|
254
|
-
if (format === 'commonjs' && ext !== '.cts') {
|
|
255
|
-
return nextLoad(url, { ...context, format });
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// If the Node.js version we're running supports TypeScript, i.e. type
|
|
259
|
-
// stripping, we hand over to the default loader. This is done for all cases
|
|
260
|
-
// except if we're loading a .ts file that's been resolved to CommonJS format.
|
|
261
|
-
// This is because these files aren't actually CommonJS in the Backstage build
|
|
262
|
-
// system, and need to be transformed to CommonJS.
|
|
263
|
-
if (
|
|
264
|
-
format === 'module-typescript' ||
|
|
265
|
-
(format === 'module-commonjs' && ext !== '.ts')
|
|
266
|
-
) {
|
|
267
|
-
return nextLoad(url, { ...context, format });
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const transformed = await transformFile(fileURLToPath(url), {
|
|
271
|
-
sourceMaps: 'inline',
|
|
272
|
-
module: {
|
|
273
|
-
type: format === 'module' ? 'es6' : 'commonjs',
|
|
274
|
-
ignoreDynamic: true,
|
|
275
|
-
|
|
276
|
-
// This helps the Node.js CommonJS compat layer identify named exports.
|
|
277
|
-
exportInteropAnnotation: true,
|
|
278
|
-
},
|
|
279
|
-
jsc: {
|
|
280
|
-
target: 'es2023',
|
|
281
|
-
parser: {
|
|
282
|
-
syntax: 'typescript',
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
return {
|
|
288
|
-
...context,
|
|
289
|
-
shortCircuit: true,
|
|
290
|
-
source: transformed.code,
|
|
291
|
-
format,
|
|
292
|
-
responseURL: url,
|
|
293
|
-
};
|
|
294
|
-
}
|
|
17
|
+
export {
|
|
18
|
+
resolve,
|
|
19
|
+
load,
|
|
20
|
+
} from '@backstage/cli-node/config/nodeTransformHooks.mjs';
|