@nx/js 0.0.0-pr-22179-271588f
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/LICENSE +22 -0
- package/README.md +68 -0
- package/babel.d.ts +13 -0
- package/babel.js +91 -0
- package/executors.json +32 -0
- package/generators.json +46 -0
- package/migrations.json +159 -0
- package/package.json +76 -0
- package/plugins/jest/local-registry.d.ts +1 -0
- package/plugins/jest/local-registry.js +4 -0
- package/src/executors/node/lib/kill-tree.d.ts +2 -0
- package/src/executors/node/lib/kill-tree.js +114 -0
- package/src/executors/node/node-with-require-overrides.d.ts +7 -0
- package/src/executors/node/node-with-require-overrides.js +21 -0
- package/src/executors/node/node.impl.d.ts +7 -0
- package/src/executors/node/node.impl.js +288 -0
- package/src/executors/node/schema.d.ts +18 -0
- package/src/executors/node/schema.json +92 -0
- package/src/executors/release-publish/format-bytes.d.ts +1 -0
- package/src/executors/release-publish/format-bytes.js +28 -0
- package/src/executors/release-publish/log-tar.d.ts +1 -0
- package/src/executors/release-publish/log-tar.js +68 -0
- package/src/executors/release-publish/release-publish.impl.d.ts +5 -0
- package/src/executors/release-publish/release-publish.impl.js +198 -0
- package/src/executors/release-publish/schema.d.ts +8 -0
- package/src/executors/release-publish/schema.json +26 -0
- package/src/executors/swc/schema.json +154 -0
- package/src/executors/swc/swc.impl.d.ts +10 -0
- package/src/executors/swc/swc.impl.js +149 -0
- package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.d.ts +5 -0
- package/src/executors/tsc/lib/batch/build-task-info-per-tsconfig-map.js +62 -0
- package/src/executors/tsc/lib/batch/index.d.ts +4 -0
- package/src/executors/tsc/lib/batch/index.js +7 -0
- package/src/executors/tsc/lib/batch/normalize-tasks-options.d.ts +3 -0
- package/src/executors/tsc/lib/batch/normalize-tasks-options.js +14 -0
- package/src/executors/tsc/lib/batch/types.d.ts +17 -0
- package/src/executors/tsc/lib/batch/types.js +2 -0
- package/src/executors/tsc/lib/batch/watch.d.ts +3 -0
- package/src/executors/tsc/lib/batch/watch.js +56 -0
- package/src/executors/tsc/lib/get-custom-transformers-factory.d.ts +3 -0
- package/src/executors/tsc/lib/get-custom-transformers-factory.js +13 -0
- package/src/executors/tsc/lib/get-task-options.d.ts +3 -0
- package/src/executors/tsc/lib/get-task-options.js +34 -0
- package/src/executors/tsc/lib/get-tsconfig.d.ts +4 -0
- package/src/executors/tsc/lib/get-tsconfig.js +86 -0
- package/src/executors/tsc/lib/index.d.ts +4 -0
- package/src/executors/tsc/lib/index.js +7 -0
- package/src/executors/tsc/lib/normalize-options.d.ts +2 -0
- package/src/executors/tsc/lib/normalize-options.js +39 -0
- package/src/executors/tsc/lib/typescript-compilation.d.ts +29 -0
- package/src/executors/tsc/lib/typescript-compilation.js +203 -0
- package/src/executors/tsc/lib/typescript-diagnostic-reporters.d.ts +3 -0
- package/src/executors/tsc/lib/typescript-diagnostic-reporters.js +37 -0
- package/src/executors/tsc/schema.json +163 -0
- package/src/executors/tsc/tsc.batch-impl.d.ts +5 -0
- package/src/executors/tsc/tsc.batch-impl.js +180 -0
- package/src/executors/tsc/tsc.impl.d.ts +7 -0
- package/src/executors/tsc/tsc.impl.js +97 -0
- package/src/executors/verdaccio/schema.d.ts +7 -0
- package/src/executors/verdaccio/schema.json +35 -0
- package/src/executors/verdaccio/verdaccio.impl.d.ts +12 -0
- package/src/executors/verdaccio/verdaccio.impl.js +220 -0
- package/src/generators/convert-to-swc/convert-to-swc.d.ts +4 -0
- package/src/generators/convert-to-swc/convert-to-swc.js +59 -0
- package/src/generators/convert-to-swc/schema.d.ts +4 -0
- package/src/generators/convert-to-swc/schema.json +36 -0
- package/src/generators/init/files/__fileName__ +20 -0
- package/src/generators/init/init.d.ts +4 -0
- package/src/generators/init/init.js +114 -0
- package/src/generators/init/schema.d.ts +7 -0
- package/src/generators/init/schema.json +36 -0
- package/src/generators/library/files/jest-config/jest.config.__ext__ +30 -0
- package/src/generators/library/files/lib/src/index.ts__tmpl__ +1 -0
- package/src/generators/library/files/lib/src/lib/__fileName__.spec.ts__tmpl__ +7 -0
- package/src/generators/library/files/lib/src/lib/__fileName__.ts__tmpl__ +3 -0
- package/src/generators/library/files/lib/tsconfig.lib.json__tmpl__ +14 -0
- package/src/generators/library/files/readme/README.md +19 -0
- package/src/generators/library/library.d.ts +16 -0
- package/src/generators/library/library.js +751 -0
- package/src/generators/library/schema.json +151 -0
- package/src/generators/release-version/release-version.d.ts +5 -0
- package/src/generators/release-version/release-version.js +390 -0
- package/src/generators/release-version/schema.d.ts +1 -0
- package/src/generators/release-version/schema.json +67 -0
- package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.d.ts +16 -0
- package/src/generators/release-version/test-utils/create-workspace-with-package-dependencies.js +40 -0
- package/src/generators/release-version/utils/package.d.ts +12 -0
- package/src/generators/release-version/utils/package.js +34 -0
- package/src/generators/release-version/utils/resolve-local-package-dependencies.d.ts +12 -0
- package/src/generators/release-version/utils/resolve-local-package-dependencies.js +78 -0
- package/src/generators/release-version/utils/resolve-version-spec.d.ts +1 -0
- package/src/generators/release-version/utils/resolve-version-spec.js +29 -0
- package/src/generators/release-version/utils/update-lock-file.d.ts +5 -0
- package/src/generators/release-version/utils/update-lock-file.js +105 -0
- package/src/generators/setup-build/generator.d.ts +4 -0
- package/src/generators/setup-build/generator.js +142 -0
- package/src/generators/setup-build/schema.d.ts +7 -0
- package/src/generators/setup-build/schema.json +42 -0
- package/src/generators/setup-verdaccio/files/config.yml +28 -0
- package/src/generators/setup-verdaccio/generator.d.ts +4 -0
- package/src/generators/setup-verdaccio/generator.js +56 -0
- package/src/generators/setup-verdaccio/schema.d.ts +3 -0
- package/src/generators/setup-verdaccio/schema.json +16 -0
- package/src/index.d.ts +17 -0
- package/src/index.js +28 -0
- package/src/internal.d.ts +4 -0
- package/src/internal.js +15 -0
- package/src/migrations/update-15-8-0/rename-swcrc-config.d.ts +2 -0
- package/src/migrations/update-15-8-0/rename-swcrc-config.js +77 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
- package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.d.ts +2 -0
- package/src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps.js +34 -0
- package/src/migrations/update-16-8-2/update-swcrc.d.ts +2 -0
- package/src/migrations/update-16-8-2/update-swcrc.js +23 -0
- package/src/migrations/update-17-0-0/remove-deprecated-build-options.d.ts +6 -0
- package/src/migrations/update-17-0-0/remove-deprecated-build-options.js +30 -0
- package/src/plugins/jest/start-local-registry.d.ts +12 -0
- package/src/plugins/jest/start-local-registry.js +63 -0
- package/src/plugins/rollup/type-definitions.d.ts +8 -0
- package/src/plugins/rollup/type-definitions.js +48 -0
- package/src/utils/add-babel-inputs.d.ts +3 -0
- package/src/utils/add-babel-inputs.js +23 -0
- package/src/utils/add-local-registry-scripts.d.ts +5 -0
- package/src/utils/add-local-registry-scripts.js +77 -0
- package/src/utils/assets/assets.d.ts +10 -0
- package/src/utils/assets/assets.js +36 -0
- package/src/utils/assets/copy-assets-handler.d.ts +32 -0
- package/src/utils/assets/copy-assets-handler.js +154 -0
- package/src/utils/assets/index.d.ts +16 -0
- package/src/utils/assets/index.js +27 -0
- package/src/utils/buildable-libs-utils.d.ts +43 -0
- package/src/utils/buildable-libs-utils.js +375 -0
- package/src/utils/check-dependencies.d.ts +8 -0
- package/src/utils/check-dependencies.js +23 -0
- package/src/utils/code-frames/highlight.d.ts +1 -0
- package/src/utils/code-frames/highlight.js +86 -0
- package/src/utils/code-frames/identifiers.d.ts +5 -0
- package/src/utils/code-frames/identifiers.js +52 -0
- package/src/utils/compiler-helper-dependency.d.ts +18 -0
- package/src/utils/compiler-helper-dependency.js +120 -0
- package/src/utils/find-npm-dependencies.d.ts +9 -0
- package/src/utils/find-npm-dependencies.js +140 -0
- package/src/utils/generate-globs.d.ts +6 -0
- package/src/utils/generate-globs.js +80 -0
- package/src/utils/get-import-path.d.ts +5 -0
- package/src/utils/get-import-path.js +14 -0
- package/src/utils/get-main-file-dir.d.ts +1 -0
- package/src/utils/get-main-file-dir.js +11 -0
- package/src/utils/inline.d.ts +19 -0
- package/src/utils/inline.js +210 -0
- package/src/utils/package-json/create-entry-points.d.ts +1 -0
- package/src/utils/package-json/create-entry-points.js +23 -0
- package/src/utils/package-json/get-npm-scope.d.ts +5 -0
- package/src/utils/package-json/get-npm-scope.js +16 -0
- package/src/utils/package-json/index.d.ts +13 -0
- package/src/utils/package-json/index.js +30 -0
- package/src/utils/package-json/update-package-json.d.ts +30 -0
- package/src/utils/package-json/update-package-json.js +179 -0
- package/src/utils/prettier.d.ts +6 -0
- package/src/utils/prettier.js +34 -0
- package/src/utils/schema.d.ts +87 -0
- package/src/utils/swc/add-swc-config.d.ts +3 -0
- package/src/utils/swc/add-swc-config.js +41 -0
- package/src/utils/swc/add-swc-dependencies.d.ts +3 -0
- package/src/utils/swc/add-swc-dependencies.js +18 -0
- package/src/utils/swc/compile-swc.d.ts +13 -0
- package/src/utils/swc/compile-swc.js +160 -0
- package/src/utils/swc/get-swcrc-path.d.ts +5 -0
- package/src/utils/swc/get-swcrc-path.js +15 -0
- package/src/utils/swc/inline.d.ts +2 -0
- package/src/utils/swc/inline.js +11 -0
- package/src/utils/typescript/__mocks__/plugin-a.d.ts +1 -0
- package/src/utils/typescript/__mocks__/plugin-a.js +5 -0
- package/src/utils/typescript/__mocks__/plugin-b.d.ts +1 -0
- package/src/utils/typescript/__mocks__/plugin-b.js +5 -0
- package/src/utils/typescript/add-tslib-dependencies.d.ts +2 -0
- package/src/utils/typescript/add-tslib-dependencies.js +11 -0
- package/src/utils/typescript/ast-utils.d.ts +32 -0
- package/src/utils/typescript/ast-utils.js +266 -0
- package/src/utils/typescript/compile-typescript-files.d.ts +10 -0
- package/src/utils/typescript/compile-typescript-files.js +43 -0
- package/src/utils/typescript/create-ts-config.d.ts +18 -0
- package/src/utils/typescript/create-ts-config.js +48 -0
- package/src/utils/typescript/ensure-typescript.d.ts +1 -0
- package/src/utils/typescript/ensure-typescript.js +9 -0
- package/src/utils/typescript/get-source-nodes.d.ts +2 -0
- package/src/utils/typescript/get-source-nodes.js +18 -0
- package/src/utils/typescript/load-ts-transformers.d.ts +5 -0
- package/src/utils/typescript/load-ts-transformers.js +62 -0
- package/src/utils/typescript/print-diagnostics.d.ts +1 -0
- package/src/utils/typescript/print-diagnostics.js +18 -0
- package/src/utils/typescript/run-type-check.d.ts +32 -0
- package/src/utils/typescript/run-type-check.js +128 -0
- package/src/utils/typescript/ts-config.d.ts +9 -0
- package/src/utils/typescript/ts-config.js +85 -0
- package/src/utils/typescript/tsnode-register.d.ts +1 -0
- package/src/utils/typescript/tsnode-register.js +24 -0
- package/src/utils/typescript/types.d.ts +18 -0
- package/src/utils/typescript/types.js +2 -0
- package/src/utils/versions.d.ts +17 -0
- package/src/utils/versions.js +21 -0
- package/src/utils/watch-for-single-file-changes.d.ts +1 -0
- package/src/utils/watch-for-single-file-changes.js +22 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addSwcConfig = exports.defaultExclude = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
exports.defaultExclude = [
|
|
6
|
+
'jest.config.ts',
|
|
7
|
+
'.*\\.spec.tsx?$',
|
|
8
|
+
'.*\\.test.tsx?$',
|
|
9
|
+
'./src/jest-setup.ts$',
|
|
10
|
+
'./**/jest-setup.ts$',
|
|
11
|
+
'.*.js$',
|
|
12
|
+
];
|
|
13
|
+
const swcOptionsString = (type = 'commonjs') => `{
|
|
14
|
+
"jsc": {
|
|
15
|
+
"target": "es2017",
|
|
16
|
+
"parser": {
|
|
17
|
+
"syntax": "typescript",
|
|
18
|
+
"decorators": true,
|
|
19
|
+
"dynamicImport": true
|
|
20
|
+
},
|
|
21
|
+
"transform": {
|
|
22
|
+
"decoratorMetadata": true,
|
|
23
|
+
"legacyDecorator": true
|
|
24
|
+
},
|
|
25
|
+
"keepClassNames": true,
|
|
26
|
+
"externalHelpers": true,
|
|
27
|
+
"loose": true
|
|
28
|
+
},
|
|
29
|
+
"module": {
|
|
30
|
+
"type": "${type}"
|
|
31
|
+
},
|
|
32
|
+
"sourceMaps": true,
|
|
33
|
+
"exclude": ${JSON.stringify(exports.defaultExclude)}
|
|
34
|
+
}`;
|
|
35
|
+
function addSwcConfig(tree, projectDir, type = 'commonjs') {
|
|
36
|
+
const swcrcPath = (0, path_1.join)(projectDir, '.swcrc');
|
|
37
|
+
if (tree.exists(swcrcPath))
|
|
38
|
+
return;
|
|
39
|
+
tree.write(swcrcPath, swcOptionsString(type));
|
|
40
|
+
}
|
|
41
|
+
exports.addSwcConfig = addSwcConfig;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addSwcRegisterDependencies = exports.addSwcDependencies = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const versions_1 = require("../versions");
|
|
6
|
+
function addSwcDependencies(tree) {
|
|
7
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {
|
|
8
|
+
'@swc/helpers': versions_1.swcHelpersVersion,
|
|
9
|
+
}, {
|
|
10
|
+
'@swc/core': versions_1.swcCoreVersion,
|
|
11
|
+
'@swc/cli': versions_1.swcCliVersion,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
exports.addSwcDependencies = addSwcDependencies;
|
|
15
|
+
function addSwcRegisterDependencies(tree) {
|
|
16
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@swc-node/register': versions_1.swcNodeVersion, '@swc/core': versions_1.swcCoreVersion });
|
|
17
|
+
}
|
|
18
|
+
exports.addSwcRegisterDependencies = addSwcRegisterDependencies;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { NormalizedSwcExecutorOptions } from '../schema';
|
|
3
|
+
export declare function compileSwc(context: ExecutorContext, normalizedOptions: NormalizedSwcExecutorOptions, postCompilationCallback: () => Promise<void>): Promise<{
|
|
4
|
+
success: boolean;
|
|
5
|
+
outfile?: undefined;
|
|
6
|
+
} | {
|
|
7
|
+
success: boolean;
|
|
8
|
+
outfile: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function compileSwcWatch(context: ExecutorContext, normalizedOptions: NormalizedSwcExecutorOptions, postCompilationCallback: () => Promise<void>): AsyncGenerator<{
|
|
11
|
+
success: boolean;
|
|
12
|
+
outfile: string;
|
|
13
|
+
}, any, undefined>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compileSwcWatch = exports.compileSwc = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const fs_extra_1 = require("fs-extra");
|
|
7
|
+
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
|
8
|
+
const print_diagnostics_1 = require("../typescript/print-diagnostics");
|
|
9
|
+
const run_type_check_1 = require("../typescript/run-type-check");
|
|
10
|
+
function getSwcCmd({ swcrcPath, srcPath, destPath }, watch = false) {
|
|
11
|
+
const swcCLI = require.resolve('@swc/cli/bin/swc.js');
|
|
12
|
+
let swcCmd = `node ${swcCLI} ${
|
|
13
|
+
// TODO(jack): clean this up when we remove inline module support
|
|
14
|
+
// Handle root project
|
|
15
|
+
srcPath === '.' ? 'src' : srcPath} -d ${srcPath === '.' ? `${destPath}/src` : destPath} --config-file=${swcrcPath}`;
|
|
16
|
+
return watch ? swcCmd.concat(' --watch') : swcCmd;
|
|
17
|
+
}
|
|
18
|
+
function getTypeCheckOptions(normalizedOptions) {
|
|
19
|
+
const { projectRoot, watch, tsConfig, root, outputPath } = normalizedOptions;
|
|
20
|
+
const typeCheckOptions = {
|
|
21
|
+
mode: 'emitDeclarationOnly',
|
|
22
|
+
tsConfigPath: tsConfig,
|
|
23
|
+
outDir: outputPath,
|
|
24
|
+
workspaceRoot: root,
|
|
25
|
+
rootDir: projectRoot,
|
|
26
|
+
};
|
|
27
|
+
if (watch) {
|
|
28
|
+
typeCheckOptions.incremental = true;
|
|
29
|
+
typeCheckOptions.cacheDir = devkit_1.cacheDir;
|
|
30
|
+
}
|
|
31
|
+
return typeCheckOptions;
|
|
32
|
+
}
|
|
33
|
+
async function compileSwc(context, normalizedOptions, postCompilationCallback) {
|
|
34
|
+
devkit_1.logger.log(`Compiling with SWC for ${context.projectName}...`);
|
|
35
|
+
if (normalizedOptions.clean) {
|
|
36
|
+
(0, fs_extra_1.removeSync)(normalizedOptions.outputPath);
|
|
37
|
+
}
|
|
38
|
+
const swcCmdLog = (0, child_process_1.execSync)(getSwcCmd(normalizedOptions.swcCliOptions), {
|
|
39
|
+
encoding: 'utf8',
|
|
40
|
+
cwd: normalizedOptions.swcCliOptions.swcCwd,
|
|
41
|
+
});
|
|
42
|
+
devkit_1.logger.log(swcCmdLog.replace(/\n/, ''));
|
|
43
|
+
const isCompileSuccess = swcCmdLog.includes('Successfully compiled');
|
|
44
|
+
if (normalizedOptions.skipTypeCheck) {
|
|
45
|
+
await postCompilationCallback();
|
|
46
|
+
return { success: isCompileSuccess };
|
|
47
|
+
}
|
|
48
|
+
const { errors, warnings } = await (0, run_type_check_1.runTypeCheck)(getTypeCheckOptions(normalizedOptions));
|
|
49
|
+
const hasErrors = errors.length > 0;
|
|
50
|
+
const hasWarnings = warnings.length > 0;
|
|
51
|
+
if (hasErrors || hasWarnings) {
|
|
52
|
+
await (0, print_diagnostics_1.printDiagnostics)(errors, warnings);
|
|
53
|
+
}
|
|
54
|
+
await postCompilationCallback();
|
|
55
|
+
return {
|
|
56
|
+
success: !hasErrors && isCompileSuccess,
|
|
57
|
+
outfile: normalizedOptions.mainOutputPath,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
exports.compileSwc = compileSwc;
|
|
61
|
+
async function* compileSwcWatch(context, normalizedOptions, postCompilationCallback) {
|
|
62
|
+
const getResult = (success) => ({
|
|
63
|
+
success,
|
|
64
|
+
outfile: normalizedOptions.mainOutputPath,
|
|
65
|
+
});
|
|
66
|
+
let typeCheckOptions;
|
|
67
|
+
let initialPostCompile = true;
|
|
68
|
+
if (normalizedOptions.clean) {
|
|
69
|
+
(0, fs_extra_1.removeSync)(normalizedOptions.outputPath);
|
|
70
|
+
}
|
|
71
|
+
return yield* (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
|
|
72
|
+
let processOnExit;
|
|
73
|
+
let stdoutOnData;
|
|
74
|
+
let stderrOnData;
|
|
75
|
+
let watcherOnExit;
|
|
76
|
+
const swcWatcher = (0, child_process_1.exec)(getSwcCmd(normalizedOptions.swcCliOptions, true), { cwd: normalizedOptions.swcCliOptions.swcCwd });
|
|
77
|
+
processOnExit = () => {
|
|
78
|
+
swcWatcher.kill();
|
|
79
|
+
done();
|
|
80
|
+
process.off('SIGINT', processOnExit);
|
|
81
|
+
process.off('SIGTERM', processOnExit);
|
|
82
|
+
process.off('exit', processOnExit);
|
|
83
|
+
};
|
|
84
|
+
stdoutOnData = async (data) => {
|
|
85
|
+
process.stdout.write(data);
|
|
86
|
+
if (!data.startsWith('Watching')) {
|
|
87
|
+
const swcStatus = data.includes('Successfully');
|
|
88
|
+
if (initialPostCompile) {
|
|
89
|
+
await postCompilationCallback();
|
|
90
|
+
initialPostCompile = false;
|
|
91
|
+
}
|
|
92
|
+
if (normalizedOptions.skipTypeCheck) {
|
|
93
|
+
next(getResult(swcStatus));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (!typeCheckOptions) {
|
|
97
|
+
typeCheckOptions = getTypeCheckOptions(normalizedOptions);
|
|
98
|
+
}
|
|
99
|
+
const delayed = delay(5000);
|
|
100
|
+
next(getResult(await Promise.race([
|
|
101
|
+
delayed
|
|
102
|
+
.start()
|
|
103
|
+
.then(() => ({ tscStatus: false, type: 'timeout' })),
|
|
104
|
+
(0, run_type_check_1.runTypeCheck)(typeCheckOptions).then(({ errors, warnings }) => {
|
|
105
|
+
const hasErrors = errors.length > 0;
|
|
106
|
+
if (hasErrors) {
|
|
107
|
+
(0, print_diagnostics_1.printDiagnostics)(errors, warnings);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
tscStatus: !hasErrors,
|
|
111
|
+
type: 'tsc',
|
|
112
|
+
};
|
|
113
|
+
}),
|
|
114
|
+
]).then(({ type, tscStatus }) => {
|
|
115
|
+
if (type === 'tsc') {
|
|
116
|
+
delayed.cancel();
|
|
117
|
+
return tscStatus && swcStatus;
|
|
118
|
+
}
|
|
119
|
+
return swcStatus;
|
|
120
|
+
})));
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
stderrOnData = (err) => {
|
|
124
|
+
process.stderr.write(err);
|
|
125
|
+
if (err.includes('Debugger attached.')) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
next(getResult(false));
|
|
129
|
+
};
|
|
130
|
+
watcherOnExit = () => {
|
|
131
|
+
done();
|
|
132
|
+
swcWatcher.off('exit', watcherOnExit);
|
|
133
|
+
};
|
|
134
|
+
swcWatcher.stdout.on('data', stdoutOnData);
|
|
135
|
+
swcWatcher.stderr.on('data', stderrOnData);
|
|
136
|
+
process.on('SIGINT', processOnExit);
|
|
137
|
+
process.on('SIGTERM', processOnExit);
|
|
138
|
+
process.on('exit', processOnExit);
|
|
139
|
+
swcWatcher.on('exit', watcherOnExit);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
exports.compileSwcWatch = compileSwcWatch;
|
|
143
|
+
function delay(ms) {
|
|
144
|
+
let timerId = undefined;
|
|
145
|
+
return {
|
|
146
|
+
start() {
|
|
147
|
+
return new Promise((resolve) => {
|
|
148
|
+
timerId = setTimeout(() => {
|
|
149
|
+
resolve();
|
|
150
|
+
}, ms);
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
cancel() {
|
|
154
|
+
if (timerId) {
|
|
155
|
+
clearTimeout(timerId);
|
|
156
|
+
timerId = undefined;
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSwcrcPath = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
function getSwcrcPath(options, contextRoot, projectRoot) {
|
|
6
|
+
const swcrcPath = options.swcrc
|
|
7
|
+
? (0, path_1.join)(contextRoot, options.swcrc)
|
|
8
|
+
: (0, path_1.join)(contextRoot, projectRoot, '.swcrc');
|
|
9
|
+
const tmpSwcrcPath = (0, path_1.join)(contextRoot, projectRoot, 'tmp', '.generated.swcrc');
|
|
10
|
+
return {
|
|
11
|
+
swcrcPath,
|
|
12
|
+
tmpSwcrcPath,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.getSwcrcPath = getSwcrcPath;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateTmpSwcrc = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
function generateTmpSwcrc(inlineProjectGraph, swcrcPath, tmpSwcrcPath) {
|
|
6
|
+
const swcrc = (0, devkit_1.readJsonFile)(swcrcPath);
|
|
7
|
+
swcrc['exclude'] = swcrc['exclude'].concat(Object.values(inlineProjectGraph.externals).map((external) => `${external.root}/**/.*.ts$`), 'node_modules/**/*.ts$');
|
|
8
|
+
(0, devkit_1.writeJsonFile)(tmpSwcrcPath, swcrc);
|
|
9
|
+
return tmpSwcrcPath;
|
|
10
|
+
}
|
|
11
|
+
exports.generateTmpSwcrc = generateTmpSwcrc;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const before: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const after: () => void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addTsLibDependencies = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const versions_1 = require("../versions");
|
|
6
|
+
function addTsLibDependencies(tree) {
|
|
7
|
+
return (0, devkit_1.addDependenciesToPackageJson)(tree, {
|
|
8
|
+
tslib: versions_1.tsLibVersion,
|
|
9
|
+
}, {});
|
|
10
|
+
}
|
|
11
|
+
exports.addTsLibDependencies = addTsLibDependencies;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Tree } from '@nx/devkit';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
import { Node, SyntaxKind } from 'typescript';
|
|
4
|
+
/**
|
|
5
|
+
* Find a module based on its import
|
|
6
|
+
*
|
|
7
|
+
* @param importExpr Import used to resolve to a module
|
|
8
|
+
* @param filePath
|
|
9
|
+
* @param tsConfigPath
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveModuleByImport(importExpr: string, filePath: string, tsConfigPath: string): string;
|
|
12
|
+
export declare function insertChange(host: Tree, sourceFile: ts.SourceFile, filePath: string, insertPosition: number, contentToInsert: string): ts.SourceFile;
|
|
13
|
+
export declare function replaceChange(host: Tree, sourceFile: ts.SourceFile, filePath: string, insertPosition: number, contentToInsert: string, oldContent: string): ts.SourceFile;
|
|
14
|
+
export declare function removeChange(host: Tree, sourceFile: ts.SourceFile, filePath: string, removePosition: number, contentToRemove: string): ts.SourceFile;
|
|
15
|
+
export declare function insertImport(host: Tree, source: ts.SourceFile, fileToEdit: string, symbolName: string, fileName: string, isDefault?: boolean): ts.SourceFile;
|
|
16
|
+
export declare function addGlobal(host: Tree, source: ts.SourceFile, modulePath: string, statement: string): ts.SourceFile;
|
|
17
|
+
export declare function getImport(source: ts.SourceFile, predicate: (a: any) => boolean): {
|
|
18
|
+
moduleSpec: string;
|
|
19
|
+
bindings: string[];
|
|
20
|
+
}[];
|
|
21
|
+
export declare function replaceNodeValue(host: Tree, sourceFile: ts.SourceFile, modulePath: string, node: ts.Node, content: string): ts.SourceFile;
|
|
22
|
+
export declare function addParameterToConstructor(tree: Tree, source: ts.SourceFile, modulePath: string, opts: {
|
|
23
|
+
className: string;
|
|
24
|
+
param: string;
|
|
25
|
+
}): ts.SourceFile;
|
|
26
|
+
export declare function addMethod(tree: Tree, source: ts.SourceFile, modulePath: string, opts: {
|
|
27
|
+
className: string;
|
|
28
|
+
methodHeader: string;
|
|
29
|
+
body?: string;
|
|
30
|
+
}): ts.SourceFile;
|
|
31
|
+
export declare function findClass(source: ts.SourceFile, className: string, silent?: boolean): ts.ClassDeclaration;
|
|
32
|
+
export declare function findNodes(node: Node, kind: SyntaxKind | SyntaxKind[], max?: number): Node[];
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findNodes = exports.findClass = exports.addMethod = exports.addParameterToConstructor = exports.replaceNodeValue = exports.getImport = exports.addGlobal = exports.insertImport = exports.removeChange = exports.replaceChange = exports.insertChange = exports.resolveModuleByImport = void 0;
|
|
4
|
+
const ensure_typescript_1 = require("./ensure-typescript");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const get_source_nodes_1 = require("./get-source-nodes");
|
|
8
|
+
const normalizedAppRoot = devkit_1.workspaceRoot.replace(/\\/g, '/');
|
|
9
|
+
let tsModule;
|
|
10
|
+
let compilerHost;
|
|
11
|
+
/**
|
|
12
|
+
* Find a module based on its import
|
|
13
|
+
*
|
|
14
|
+
* @param importExpr Import used to resolve to a module
|
|
15
|
+
* @param filePath
|
|
16
|
+
* @param tsConfigPath
|
|
17
|
+
*/
|
|
18
|
+
function resolveModuleByImport(importExpr, filePath, tsConfigPath) {
|
|
19
|
+
compilerHost = compilerHost || getCompilerHost(tsConfigPath);
|
|
20
|
+
const { options, host, moduleResolutionCache } = compilerHost;
|
|
21
|
+
const { resolvedModule } = tsModule.resolveModuleName(importExpr, filePath, options, host, moduleResolutionCache);
|
|
22
|
+
if (!resolvedModule) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return resolvedModule.resolvedFileName.replace(`${normalizedAppRoot}/`, '');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.resolveModuleByImport = resolveModuleByImport;
|
|
30
|
+
function getCompilerHost(tsConfigPath) {
|
|
31
|
+
const options = readTsConfigOptions(tsConfigPath);
|
|
32
|
+
const host = tsModule.createCompilerHost(options, true);
|
|
33
|
+
const moduleResolutionCache = tsModule.createModuleResolutionCache(devkit_1.workspaceRoot, host.getCanonicalFileName);
|
|
34
|
+
return { options, host, moduleResolutionCache };
|
|
35
|
+
}
|
|
36
|
+
function readTsConfigOptions(tsConfigPath) {
|
|
37
|
+
if (!tsModule) {
|
|
38
|
+
tsModule = require('typescript');
|
|
39
|
+
}
|
|
40
|
+
const readResult = tsModule.readConfigFile(tsConfigPath, tsModule.sys.readFile);
|
|
41
|
+
// we don't need to scan the files, we only care about options
|
|
42
|
+
const host = {
|
|
43
|
+
readDirectory: () => [],
|
|
44
|
+
readFile: () => '',
|
|
45
|
+
fileExists: tsModule.sys.fileExists,
|
|
46
|
+
};
|
|
47
|
+
return tsModule.parseJsonConfigFileContent(readResult.config, host, (0, path_1.dirname)(tsConfigPath)).options;
|
|
48
|
+
}
|
|
49
|
+
function nodesByPosition(first, second) {
|
|
50
|
+
return first.getStart() - second.getStart();
|
|
51
|
+
}
|
|
52
|
+
function updateTsSourceFile(host, sourceFile, filePath) {
|
|
53
|
+
const newFileContents = host.read(filePath).toString('utf-8');
|
|
54
|
+
return sourceFile.update(newFileContents, {
|
|
55
|
+
newLength: newFileContents.length,
|
|
56
|
+
span: {
|
|
57
|
+
length: sourceFile.text.length,
|
|
58
|
+
start: 0,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function insertChange(host, sourceFile, filePath, insertPosition, contentToInsert) {
|
|
63
|
+
const content = host.read(filePath).toString();
|
|
64
|
+
const prefix = content.substring(0, insertPosition);
|
|
65
|
+
const suffix = content.substring(insertPosition);
|
|
66
|
+
host.write(filePath, `${prefix}${contentToInsert}${suffix}`);
|
|
67
|
+
return updateTsSourceFile(host, sourceFile, filePath);
|
|
68
|
+
}
|
|
69
|
+
exports.insertChange = insertChange;
|
|
70
|
+
function replaceChange(host, sourceFile, filePath, insertPosition, contentToInsert, oldContent) {
|
|
71
|
+
const content = host.read(filePath, 'utf-8');
|
|
72
|
+
const prefix = content.substring(0, insertPosition);
|
|
73
|
+
const suffix = content.substring(insertPosition + oldContent.length);
|
|
74
|
+
const text = content.substring(insertPosition, insertPosition + oldContent.length);
|
|
75
|
+
if (text !== oldContent) {
|
|
76
|
+
throw new Error(`Invalid replace: "${text}" != "${oldContent}".`);
|
|
77
|
+
}
|
|
78
|
+
host.write(filePath, `${prefix}${contentToInsert}${suffix}`);
|
|
79
|
+
return updateTsSourceFile(host, sourceFile, filePath);
|
|
80
|
+
}
|
|
81
|
+
exports.replaceChange = replaceChange;
|
|
82
|
+
function removeChange(host, sourceFile, filePath, removePosition, contentToRemove) {
|
|
83
|
+
const content = host.read(filePath).toString();
|
|
84
|
+
const prefix = content.substring(0, removePosition);
|
|
85
|
+
const suffix = content.substring(removePosition + contentToRemove.length);
|
|
86
|
+
host.write(filePath, `${prefix}${suffix}`);
|
|
87
|
+
return updateTsSourceFile(host, sourceFile, filePath);
|
|
88
|
+
}
|
|
89
|
+
exports.removeChange = removeChange;
|
|
90
|
+
function insertImport(host, source, fileToEdit, symbolName, fileName, isDefault = false) {
|
|
91
|
+
if (!tsModule) {
|
|
92
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
93
|
+
}
|
|
94
|
+
const rootNode = source;
|
|
95
|
+
const allImports = findNodes(rootNode, tsModule.SyntaxKind.ImportDeclaration);
|
|
96
|
+
// get nodes that map to import statements from the file fileName
|
|
97
|
+
const relevantImports = allImports.filter((node) => {
|
|
98
|
+
// StringLiteral of the ImportDeclaration is the import file (fileName in this case).
|
|
99
|
+
const importFiles = node
|
|
100
|
+
.getChildren()
|
|
101
|
+
.filter((child) => child.kind === tsModule.SyntaxKind.StringLiteral)
|
|
102
|
+
.map((n) => n.text);
|
|
103
|
+
return importFiles.filter((file) => file === fileName).length === 1;
|
|
104
|
+
});
|
|
105
|
+
if (relevantImports.length > 0) {
|
|
106
|
+
let importsAsterisk = false;
|
|
107
|
+
// imports from import file
|
|
108
|
+
const imports = [];
|
|
109
|
+
relevantImports.forEach((n) => {
|
|
110
|
+
Array.prototype.push.apply(imports, findNodes(n, tsModule.SyntaxKind.Identifier));
|
|
111
|
+
if (findNodes(n, tsModule.SyntaxKind.AsteriskToken).length > 0) {
|
|
112
|
+
importsAsterisk = true;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
// if imports * from fileName, don't add symbolName
|
|
116
|
+
if (importsAsterisk) {
|
|
117
|
+
return source;
|
|
118
|
+
}
|
|
119
|
+
const importTextNodes = imports.filter((n) => n.text === symbolName);
|
|
120
|
+
// insert import if it's not there
|
|
121
|
+
if (importTextNodes.length === 0) {
|
|
122
|
+
const fallbackPos = findNodes(relevantImports[0], tsModule.SyntaxKind.CloseBraceToken)[0].getStart() ||
|
|
123
|
+
findNodes(relevantImports[0], tsModule.SyntaxKind.FromKeyword)[0].getStart();
|
|
124
|
+
return insertAfterLastOccurrence(host, source, imports, `, ${symbolName}`, fileToEdit, fallbackPos);
|
|
125
|
+
}
|
|
126
|
+
return source;
|
|
127
|
+
}
|
|
128
|
+
// no such import declaration exists
|
|
129
|
+
const useStrict = findNodes(rootNode, tsModule.SyntaxKind.StringLiteral).filter((n) => n.text === 'use strict');
|
|
130
|
+
let fallbackPos = 0;
|
|
131
|
+
if (useStrict.length > 0) {
|
|
132
|
+
fallbackPos = useStrict[0].end;
|
|
133
|
+
}
|
|
134
|
+
const open = isDefault ? '' : '{ ';
|
|
135
|
+
const close = isDefault ? '' : ' }';
|
|
136
|
+
// if there are no imports or 'use strict' statement, insert import at beginning of file
|
|
137
|
+
const insertAtBeginning = allImports.length === 0 && useStrict.length === 0;
|
|
138
|
+
const separator = insertAtBeginning ? '' : ';\n';
|
|
139
|
+
const toInsert = `${separator}import ${open}${symbolName}${close}` +
|
|
140
|
+
` from '${fileName}'${insertAtBeginning ? ';\n' : ''}`;
|
|
141
|
+
return insertAfterLastOccurrence(host, source, allImports, toInsert, fileToEdit, fallbackPos, tsModule.SyntaxKind.StringLiteral);
|
|
142
|
+
}
|
|
143
|
+
exports.insertImport = insertImport;
|
|
144
|
+
function insertAfterLastOccurrence(host, sourceFile, nodes, toInsert, pathToFile, fallbackPos, syntaxKind) {
|
|
145
|
+
// sort() has a side effect, so make a copy so that we won't overwrite the parent's object.
|
|
146
|
+
let lastItem = [...nodes].sort(nodesByPosition).pop();
|
|
147
|
+
if (!lastItem) {
|
|
148
|
+
throw new Error();
|
|
149
|
+
}
|
|
150
|
+
if (syntaxKind) {
|
|
151
|
+
lastItem = findNodes(lastItem, syntaxKind).sort(nodesByPosition).pop();
|
|
152
|
+
}
|
|
153
|
+
if (!lastItem && fallbackPos == undefined) {
|
|
154
|
+
throw new Error(`tried to insert ${toInsert} as first occurrence with no fallback position`);
|
|
155
|
+
}
|
|
156
|
+
const lastItemPosition = lastItem ? lastItem.getEnd() : fallbackPos;
|
|
157
|
+
return insertChange(host, sourceFile, pathToFile, lastItemPosition, toInsert);
|
|
158
|
+
}
|
|
159
|
+
function addGlobal(host, source, modulePath, statement) {
|
|
160
|
+
if (!tsModule) {
|
|
161
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
162
|
+
}
|
|
163
|
+
const allImports = findNodes(source, tsModule.SyntaxKind.ImportDeclaration);
|
|
164
|
+
if (allImports.length > 0) {
|
|
165
|
+
const lastImport = allImports[allImports.length - 1];
|
|
166
|
+
return insertChange(host, source, modulePath, lastImport.end + 1, `\n${statement}\n`);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return insertChange(host, source, modulePath, 0, `${statement}\n`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.addGlobal = addGlobal;
|
|
173
|
+
function getImport(source, predicate) {
|
|
174
|
+
if (!tsModule) {
|
|
175
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
176
|
+
}
|
|
177
|
+
const allImports = findNodes(source, tsModule.SyntaxKind.ImportDeclaration);
|
|
178
|
+
const matching = allImports.filter((i) => predicate(i.moduleSpecifier.getText()));
|
|
179
|
+
return matching.map((i) => {
|
|
180
|
+
const moduleSpec = i.moduleSpecifier
|
|
181
|
+
.getText()
|
|
182
|
+
.substring(1, i.moduleSpecifier.getText().length - 1);
|
|
183
|
+
const t = i.importClause.namedBindings.getText();
|
|
184
|
+
const bindings = t
|
|
185
|
+
.replace('{', '')
|
|
186
|
+
.replace('}', '')
|
|
187
|
+
.split(',')
|
|
188
|
+
.map((q) => q.trim());
|
|
189
|
+
return { moduleSpec, bindings };
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
exports.getImport = getImport;
|
|
193
|
+
function replaceNodeValue(host, sourceFile, modulePath, node, content) {
|
|
194
|
+
return replaceChange(host, sourceFile, modulePath, node.getStart(node.getSourceFile()), content, node.getText());
|
|
195
|
+
}
|
|
196
|
+
exports.replaceNodeValue = replaceNodeValue;
|
|
197
|
+
function addParameterToConstructor(tree, source, modulePath, opts) {
|
|
198
|
+
if (!tsModule) {
|
|
199
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
200
|
+
}
|
|
201
|
+
const clazz = findClass(source, opts.className);
|
|
202
|
+
const constructor = clazz.members.filter((m) => m.kind === tsModule.SyntaxKind.Constructor)[0];
|
|
203
|
+
if (constructor) {
|
|
204
|
+
throw new Error('Should be tested'); // TODO: check this
|
|
205
|
+
}
|
|
206
|
+
return addMethod(tree, source, modulePath, {
|
|
207
|
+
className: opts.className,
|
|
208
|
+
methodHeader: `constructor(${opts.param})`,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
exports.addParameterToConstructor = addParameterToConstructor;
|
|
212
|
+
function addMethod(tree, source, modulePath, opts) {
|
|
213
|
+
const clazz = findClass(source, opts.className);
|
|
214
|
+
const body = opts.body
|
|
215
|
+
? `
|
|
216
|
+
${opts.methodHeader} {
|
|
217
|
+
${opts.body}
|
|
218
|
+
}
|
|
219
|
+
`
|
|
220
|
+
: `
|
|
221
|
+
${opts.methodHeader} {}
|
|
222
|
+
`;
|
|
223
|
+
return insertChange(tree, source, modulePath, clazz.end - 1, body);
|
|
224
|
+
}
|
|
225
|
+
exports.addMethod = addMethod;
|
|
226
|
+
function findClass(source, className, silent = false) {
|
|
227
|
+
if (!tsModule) {
|
|
228
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
229
|
+
}
|
|
230
|
+
const nodes = (0, get_source_nodes_1.getSourceNodes)(source);
|
|
231
|
+
const clazz = nodes.filter((n) => n.kind === tsModule.SyntaxKind.ClassDeclaration &&
|
|
232
|
+
n.name.text === className)[0];
|
|
233
|
+
if (!clazz && !silent) {
|
|
234
|
+
throw new Error(`Cannot find class '${className}'.`);
|
|
235
|
+
}
|
|
236
|
+
return clazz;
|
|
237
|
+
}
|
|
238
|
+
exports.findClass = findClass;
|
|
239
|
+
function findNodes(node, kind, max = Infinity) {
|
|
240
|
+
if (!node || max == 0) {
|
|
241
|
+
return [];
|
|
242
|
+
}
|
|
243
|
+
const arr = [];
|
|
244
|
+
const hasMatch = Array.isArray(kind)
|
|
245
|
+
? kind.includes(node.kind)
|
|
246
|
+
: node.kind === kind;
|
|
247
|
+
if (hasMatch) {
|
|
248
|
+
arr.push(node);
|
|
249
|
+
max--;
|
|
250
|
+
}
|
|
251
|
+
if (max > 0) {
|
|
252
|
+
for (const child of node.getChildren()) {
|
|
253
|
+
findNodes(child, kind, max).forEach((node) => {
|
|
254
|
+
if (max > 0) {
|
|
255
|
+
arr.push(node);
|
|
256
|
+
}
|
|
257
|
+
max--;
|
|
258
|
+
});
|
|
259
|
+
if (max <= 0) {
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return arr;
|
|
265
|
+
}
|
|
266
|
+
exports.findNodes = findNodes;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TypeScriptCompilationOptions } from '@nx/workspace/src/utilities/typescript/compilation';
|
|
2
|
+
import { NormalizedExecutorOptions } from '../schema';
|
|
3
|
+
export interface TypescriptCompilationResult {
|
|
4
|
+
success: boolean;
|
|
5
|
+
outfile: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function compileTypeScriptFiles(normalizedOptions: NormalizedExecutorOptions, tscOptions: TypeScriptCompilationOptions, postCompilationCallback: () => void | Promise<void>): {
|
|
8
|
+
iterator: AsyncIterable<TypescriptCompilationResult>;
|
|
9
|
+
close: () => void | Promise<void>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compileTypeScriptFiles = void 0;
|
|
4
|
+
const compilation_1 = require("@nx/workspace/src/utilities/typescript/compilation");
|
|
5
|
+
const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
|
|
6
|
+
const TYPESCRIPT_FOUND_N_ERRORS_WATCHING_FOR_FILE_CHANGES = 6194;
|
|
7
|
+
// Typescript diagnostic message for 6194: Found {0} errors. Watching for file changes.
|
|
8
|
+
// https://github.com/microsoft/TypeScript/blob/d45012c5e2ab122919ee4777a7887307c5f4a1e0/src/compiler/diagnosticMessages.json#L4763-L4766
|
|
9
|
+
const ERROR_COUNT_REGEX = /Found (\d+) errors/;
|
|
10
|
+
function getErrorCountFromMessage(messageText) {
|
|
11
|
+
return Number.parseInt(ERROR_COUNT_REGEX.exec(messageText)[1]);
|
|
12
|
+
}
|
|
13
|
+
function compileTypeScriptFiles(normalizedOptions, tscOptions, postCompilationCallback) {
|
|
14
|
+
const getResult = (success) => ({
|
|
15
|
+
success,
|
|
16
|
+
outfile: normalizedOptions.mainOutputPath,
|
|
17
|
+
});
|
|
18
|
+
let tearDown;
|
|
19
|
+
return {
|
|
20
|
+
iterator: (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
|
|
21
|
+
if (normalizedOptions.watch) {
|
|
22
|
+
const host = (0, compilation_1.compileTypeScriptWatcher)(tscOptions, async (d) => {
|
|
23
|
+
if (d.code === TYPESCRIPT_FOUND_N_ERRORS_WATCHING_FOR_FILE_CHANGES) {
|
|
24
|
+
await postCompilationCallback();
|
|
25
|
+
next(getResult(getErrorCountFromMessage(d.messageText) === 0));
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
tearDown = () => {
|
|
29
|
+
host.close();
|
|
30
|
+
done();
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const { success } = (0, compilation_1.compileTypeScript)(tscOptions);
|
|
35
|
+
await postCompilationCallback();
|
|
36
|
+
next(getResult(success));
|
|
37
|
+
done();
|
|
38
|
+
}
|
|
39
|
+
}),
|
|
40
|
+
close: () => tearDown?.(),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.compileTypeScriptFiles = compileTypeScriptFiles;
|