@mouryaamit/nx-polystack 1.7.0 → 1.8.4

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.
Files changed (50) hide show
  1. package/README.md +17 -14
  2. package/dist/bin/cli.js +11 -1
  3. package/dist/bin/cli.js.map +1 -1
  4. package/dist/generators.json +5 -0
  5. package/dist/src/cli/commands/adopt-compare.d.ts +14 -0
  6. package/dist/src/cli/commands/adopt-compare.js +165 -0
  7. package/dist/src/cli/commands/adopt-compare.js.map +1 -0
  8. package/dist/src/cli/commands/adopt.d.ts +6 -0
  9. package/dist/src/cli/commands/adopt.js +63 -0
  10. package/dist/src/cli/commands/adopt.js.map +1 -0
  11. package/dist/src/cli/commands/index.js +1 -0
  12. package/dist/src/cli/commands/index.js.map +1 -1
  13. package/dist/src/cli/commands/update.js +19 -0
  14. package/dist/src/cli/commands/update.js.map +1 -1
  15. package/dist/src/cli/commands/upgrade.d.ts +11 -0
  16. package/dist/src/cli/commands/upgrade.js +257 -4
  17. package/dist/src/cli/commands/upgrade.js.map +1 -1
  18. package/dist/src/cli/help.js +30 -0
  19. package/dist/src/cli/help.js.map +1 -1
  20. package/dist/src/cli/launcher.d.ts +12 -0
  21. package/dist/src/cli/launcher.js +41 -1
  22. package/dist/src/cli/launcher.js.map +1 -1
  23. package/dist/src/generators/adopt/generator.d.ts +42 -0
  24. package/dist/src/generators/adopt/generator.js +476 -0
  25. package/dist/src/generators/adopt/generator.js.map +1 -0
  26. package/dist/src/generators/adopt/old-scripts.d.ts +24 -0
  27. package/dist/src/generators/adopt/old-scripts.js +155 -0
  28. package/dist/src/generators/adopt/old-scripts.js.map +1 -0
  29. package/dist/src/generators/adopt/pipeline.d.ts +31 -0
  30. package/dist/src/generators/adopt/pipeline.js +133 -0
  31. package/dist/src/generators/adopt/pipeline.js.map +1 -0
  32. package/dist/src/generators/adopt/schema.json +26 -0
  33. package/dist/src/generators/migrate/adapters/nx-workspace.js +1 -47
  34. package/dist/src/generators/migrate/adapters/nx-workspace.js.map +1 -1
  35. package/dist/src/generators/migrate/nx/build-scripts.d.ts +8 -0
  36. package/dist/src/generators/migrate/nx/build-scripts.js +50 -1
  37. package/dist/src/generators/migrate/nx/build-scripts.js.map +1 -1
  38. package/dist/src/lib/adopt/compare.d.ts +14 -0
  39. package/dist/src/lib/adopt/compare.js +179 -0
  40. package/dist/src/lib/adopt/compare.js.map +1 -0
  41. package/dist/src/lib/upgrade/nx-migrate.d.ts +46 -0
  42. package/dist/src/lib/upgrade/nx-migrate.js +166 -0
  43. package/dist/src/lib/upgrade/nx-migrate.js.map +1 -0
  44. package/dist/src/lib/utils/devkit-pin.d.ts +15 -0
  45. package/dist/src/lib/utils/devkit-pin.js +61 -0
  46. package/dist/src/lib/utils/devkit-pin.js.map +1 -0
  47. package/dist/src/lib/utils/json-layout.d.ts +37 -0
  48. package/dist/src/lib/utils/json-layout.js +260 -0
  49. package/dist/src/lib/utils/json-layout.js.map +1 -0
  50. package/package.json +1 -1
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findOldScripts = exports.recordedScripts = exports.toolScripts = exports.liveScripts = exports.scriptClosure = exports.scriptReferences = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path = tslib_1.__importStar(require("path"));
6
+ /**
7
+ * The workspace's own build scripts that `pstack adopt` replaced, found by following what each
8
+ * script runs, and whether anything still uses them.
9
+ */
10
+ const JS = /\.(?:c|m)?js$/;
11
+ const posix = path.posix;
12
+ /** Workspace-relative .js files a script's text runs or loads (only those that exist). */
13
+ function scriptReferences(tree, rel, text) {
14
+ const dir = rel ? posix.dirname(rel) : '.';
15
+ const out = new Set();
16
+ const add = (p) => {
17
+ const n = posix.normalize(p.replace(/^\.\//, ''));
18
+ const file = JS.test(n) ? n : `${n}.js`;
19
+ if (!file.startsWith('..') && tree.exists(file))
20
+ out.add(file);
21
+ };
22
+ // node tools/scripts/x.js …
23
+ for (const m of text.matchAll(/\bnode\s+(['"]?)([\w./-]+\.(?:c|m)?js)\1/g))
24
+ add(m[2]);
25
+ // require('./x'), import … from './x', import './x' and import('./x')
26
+ for (const m of text.matchAll(/(?:\brequire\(\s*|\bfrom\s+|\bimport\(\s*|\bimport\s+)['"](\.{1,2}\/[\w./-]+)['"]/g)) {
27
+ add(posix.join(dir, m[1]));
28
+ }
29
+ // path.join('tools', 'scripts', 'x.js') or path.join(__dirname, 'x.js')
30
+ for (const m of text.matchAll(/\bpath\.(?:join|resolve)\(([^()]*)\)/g)) {
31
+ const parts = [...m[1].matchAll(/['"]([\w./-]+)['"]/g)].map((p) => p[1]);
32
+ if (parts.length === 0 || !JS.test(parts[parts.length - 1]))
33
+ continue;
34
+ add(/__dirname/.test(m[1]) ? posix.join(dir, ...parts) : posix.join(...parts));
35
+ }
36
+ // A bare 'tools/…/x.js' string (spawn arguments, config files).
37
+ for (const m of text.matchAll(/['"`]((?:\.\/)?tools\/[\w./-]+\.(?:c|m)?js)['"`]/g))
38
+ add(m[1]);
39
+ return [...out].sort();
40
+ }
41
+ exports.scriptReferences = scriptReferences;
42
+ /** `entries` and every script they run or load, transitively. */
43
+ function scriptClosure(tree, entries) {
44
+ const seen = new Set();
45
+ const visit = (rel) => {
46
+ if (seen.has(rel) || !tree.exists(rel))
47
+ return;
48
+ seen.add(rel);
49
+ const text = tree.read(rel, 'utf8') ?? '';
50
+ for (const ref of scriptReferences(tree, rel, text))
51
+ visit(ref);
52
+ };
53
+ for (const e of entries)
54
+ visit(e);
55
+ return seen;
56
+ }
57
+ exports.scriptClosure = scriptClosure;
58
+ const SKIP_DIRS = new Set(['node_modules', 'dist', 'tmp', 'coverage', '.git', '.nx', '.angular']);
59
+ function walk(tree, dir, keep, out, depth = 0) {
60
+ if (depth > 8)
61
+ return;
62
+ for (const name of tree.children(dir)) {
63
+ if (SKIP_DIRS.has(name))
64
+ continue;
65
+ const rel = dir === '.' || dir === '' ? name : `${dir}/${name}`;
66
+ if (tree.isFile(rel)) {
67
+ if (keep(rel))
68
+ out.push(rel);
69
+ }
70
+ else {
71
+ walk(tree, rel, keep, out, depth + 1);
72
+ }
73
+ }
74
+ }
75
+ /** App and library code (outside tools/) that can import a script from tools/. */
76
+ const SOURCE = /^(?!tools\/).+\.(?:[cm]?[jt]sx?)$/;
77
+ /**
78
+ * Text files that can start or load a script: package.json, project.json, CI, git hooks, and the
79
+ * apps' and libraries' own code (an app importing tools/scripts/x.js at runtime).
80
+ */
81
+ function entryTexts(tree) {
82
+ const files = [];
83
+ walk(tree, '.', (rel) => {
84
+ const base = posix.basename(rel);
85
+ return ((SOURCE.test(rel) && !/\.d\.ts$/.test(rel)) ||
86
+ base === 'package.json' ||
87
+ base === 'project.json' ||
88
+ /^Jenkinsfile/.test(base) ||
89
+ /^(\.gitlab-ci|azure-pipelines|bitbucket-pipelines)\.ya?ml$/.test(base) ||
90
+ /^\.github\/workflows\/[^/]+\.ya?ml$/.test(rel) ||
91
+ /^\.husky\/[^/]+$/.test(rel) ||
92
+ /^\.lintstagedrc/.test(base));
93
+ }, files);
94
+ return files.map((file) => ({ file, text: tree.read(file, 'utf8') ?? '' }));
95
+ }
96
+ /** Scripts under tools/ that something outside tools/ still starts (and what they load). */
97
+ function liveScripts(tree) {
98
+ const entries = new Set();
99
+ for (const { file, text } of entryTexts(tree)) {
100
+ for (const ref of scriptReferences(tree, file, text))
101
+ entries.add(ref);
102
+ }
103
+ return scriptClosure(tree, [...entries]);
104
+ }
105
+ exports.liveScripts = liveScripts;
106
+ /** Every .js file under tools/. */
107
+ function toolScripts(tree) {
108
+ const out = [];
109
+ if (tree.exists('tools'))
110
+ walk(tree, 'tools', (rel) => JS.test(rel), out);
111
+ return out.sort();
112
+ }
113
+ exports.toolScripts = toolScripts;
114
+ /** A script that builds apps itself: runs nx/ng build for a project. */
115
+ const BUILD_DRIVER = /\b(?:npx\s+)?nx\s+(?:build|run-many\s[^`'"]*\bbuild\b|run\s+[^`'"\s]+:build)|\bng\s+build\b/;
116
+ /** A script that runs the per-app npm build scripts (`npm run build:<app>:<env>`). */
117
+ const RUNS_BUILD_SCRIPTS = /\bnpm\b[^\n]{0,30}['"`]run['"`]|\bnpm\s+run\s+build:/;
118
+ /** Workspace-relative script paths named in backticks in a report (`tools/scripts/build.js`). */
119
+ function recordedScripts(report) {
120
+ return [
121
+ ...new Set([...report.matchAll(/`((?:\.\/)?tools\/[\w./-]+\.(?:c|m)?js)\b[^`]*`/g)].map((m) => posix.normalize(m[1]))),
122
+ ].sort();
123
+ }
124
+ exports.recordedScripts = recordedScripts;
125
+ /**
126
+ * The old build pipeline: the scripts recorded as replaced by adopt (`recorded`), plus any
127
+ * unused script under tools/ that runs an Angular build, with everything they run or load. Of
128
+ * those, the files nothing else uses (package.json, project.json, CI, git hooks, and the scripts
129
+ * those start) can go.
130
+ */
131
+ function findOldScripts(tree, recorded) {
132
+ const live = liveScripts(tree);
133
+ const all = toolScripts(tree);
134
+ const unused = all.filter((f) => !live.has(f));
135
+ const drivers = unused.filter((f) => {
136
+ const text = tree.read(f, 'utf8') ?? '';
137
+ return BUILD_DRIVER.test(text) || RUNS_BUILD_SCRIPTS.test(text);
138
+ });
139
+ const entries = [...new Set([...recorded.filter((r) => tree.exists(r)), ...drivers])];
140
+ // A script that only starts drivers (build-all.js running npm run build:<app>:<env> or
141
+ // build.js) belongs to the pipeline too.
142
+ for (const f of unused) {
143
+ if (entries.includes(f))
144
+ continue;
145
+ const reached = scriptClosure(tree, [f]);
146
+ if ([...reached].some((r) => r !== f && entries.includes(r)))
147
+ entries.push(f);
148
+ }
149
+ const pipeline = scriptClosure(tree, entries);
150
+ const removable = [...pipeline].filter((f) => !live.has(f)).sort();
151
+ const unreferenced = unused.filter((f) => !pipeline.has(f)).sort();
152
+ return { removable, unreferenced };
153
+ }
154
+ exports.findOldScripts = findOldScripts;
155
+ //# sourceMappingURL=old-scripts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"old-scripts.js","sourceRoot":"","sources":["../../../../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CAAC;IACH,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACtF,uFAAuF;IACvF,yCAAyC;IACzC,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;QACtB,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;YAAE,SAAS;QAClC,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACzC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KAC/E;IACD,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC9C,MAAM,SAAS,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACnE,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACnE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;AACrC,CAAC;AApBD,wCAoBC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * What a workspace's own build script (e.g. tools/scripts/build.js) does after `nx build`, read
3
+ * from it and the scripts it runs, so the release target can do the same.
4
+ */
5
+ export interface SourcePipeline {
6
+ /** The script files read (workspace-relative), sorted. */
7
+ scripts: string[];
8
+ /** CSP nonce written into index.html; undefined when no step writes one. */
9
+ nonce?: {
10
+ placeholder?: string;
11
+ tags?: 'all' | 'legacy';
12
+ position?: 'end' | 'after-tag-name';
13
+ replaceTokens: string[];
14
+ addMeta: boolean;
15
+ };
16
+ /** HTML comments removed from index.html in every env. */
17
+ stripHtmlComments: boolean;
18
+ /** Comments removed from the built JS/CSS (UAT/PROD). */
19
+ stripComments: boolean;
20
+ /** The app's JS obfuscated (UAT/PROD), as the release executor's `obfuscate` profile. */
21
+ obfuscate?: ObfuscateProfile;
22
+ /** javascript-obfuscator options the script sets that differ from that preset. */
23
+ obfuscateOptions?: Record<string, unknown>;
24
+ /** Console calls removed from the built JS. */
25
+ dropConsole: boolean;
26
+ /** IANA time zone the build stamp is written in (from a `timeZone: '…'` option). */
27
+ timezone?: string;
28
+ }
29
+ export type ObfuscateProfile = 'light' | 'medium' | 'strong';
30
+ /** Reads the custom build scripts and the step scripts they run. */
31
+ export declare function readSourcePipeline(root: string, buildScripts: string[]): SourcePipeline;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readSourcePipeline = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const path = tslib_1.__importStar(require("path"));
7
+ /** What the release executor's presets set for the options read from a script (see hardening/obfuscate.ts). */
8
+ const PRESET_VALUES = {
9
+ light: {
10
+ stringArrayThreshold: 0.5,
11
+ identifierNamesGenerator: 'mangled',
12
+ stringArrayWrappersCount: 0,
13
+ },
14
+ medium: {
15
+ stringArrayThreshold: 0.75,
16
+ identifierNamesGenerator: 'hexadecimal',
17
+ stringArrayWrappersCount: 1,
18
+ },
19
+ };
20
+ /** `key: value` (number, quoted string or boolean) in a block of javascript-obfuscator options. */
21
+ function optionValue(block, key) {
22
+ const m = new RegExp(`\\b${key}\\s*:\\s*(?:(['"\`])([\\w-]+)\\1|([\\d.]+)|(true|false))`).exec(block);
23
+ if (!m)
24
+ return undefined;
25
+ if (m[2] !== undefined)
26
+ return m[2];
27
+ if (m[3] !== undefined)
28
+ return Number(m[3]);
29
+ return m[4] === 'true';
30
+ }
31
+ /**
32
+ * The preset and overrides matching an obfuscate script: its shared options plus the profile it
33
+ * runs by default (`process.env.X || 'light'` picking a `light: { … }` block). Hexadecimal names
34
+ * map to medium, anything else to light; the options that then differ become overrides.
35
+ */
36
+ function obfuscateSettings(text) {
37
+ const named = /\bprocess\.env\.\w*PROFILE\w*\s*(?:\|\||\?\?)\s*['"`](\w+)['"`]/.exec(text)?.[1];
38
+ if (named === 'medium' || named === 'strong')
39
+ return { obfuscate: named };
40
+ const profileBlock = named
41
+ ? new RegExp(`\\b${named}\\s*:\\s*\\{([^}]*)\\}`).exec(text)?.[1] ?? ''
42
+ : '';
43
+ const read = (key) => optionValue(profileBlock, key) ?? optionValue(text, key);
44
+ const names = read('identifierNamesGenerator');
45
+ const preset = names === 'hexadecimal' ? 'medium' : 'light';
46
+ const overrides = {};
47
+ for (const [key, presetValue] of Object.entries(PRESET_VALUES[preset])) {
48
+ const value = read(key);
49
+ if (value !== undefined && value !== presetValue)
50
+ overrides[key] = value;
51
+ }
52
+ return Object.keys(overrides).length > 0
53
+ ? { obfuscate: preset, obfuscateOptions: overrides }
54
+ : { obfuscate: preset };
55
+ }
56
+ const read = (root, rel) => {
57
+ try {
58
+ return fs.readFileSync(path.join(root, ...rel.split('/')), 'utf8');
59
+ }
60
+ catch {
61
+ return undefined;
62
+ }
63
+ };
64
+ /** `node <dir>/<x>.js` calls in a script's text, as workspace-relative paths. */
65
+ function calledScripts(text) {
66
+ const out = new Set();
67
+ for (const m of text.matchAll(/\bnode\s+(['"]?)([\w./-]+\.(?:c|m)?js)\1/g)) {
68
+ out.add(path.posix.normalize(m[2].replace(/^\.\//, '')));
69
+ }
70
+ // `run(\`node tools/scripts/x.js …\`)` is the common form; plain requires are helpers, not steps.
71
+ return [...out].sort();
72
+ }
73
+ /** The nonce settings of a script that puts a nonce placeholder on index.html tags. */
74
+ function nonceOf(text) {
75
+ if (!/\bnonce\b/i.test(text) || !/<script/i.test(text))
76
+ return undefined;
77
+ const placeholder = /\bconst\s+NONCE\s*=\s*(['"`])((?:(?!\1).)*)\1/.exec(text)?.[2];
78
+ // Inline scripts only: the <script pattern skips tags with src.
79
+ const tags = /<script\(\?!\[\^>\]\*\\bsrc=\)/.test(text) ? 'legacy' : undefined;
80
+ const position = /`<(?:script|link|style) nonce=/.test(text) ? 'after-tag-name' : undefined;
81
+ const replaceTokens = [
82
+ ...new Set([...text.matchAll(/\.replace\(\/([A-Za-z0-9_-]{4,})\/g,\s*NONCE\)/g)].map((m) => m[1])),
83
+ ].sort();
84
+ const addMeta = /property=\\?["']csp-nonce/.test(text);
85
+ return { placeholder, tags, position, replaceTokens, addMeta };
86
+ }
87
+ /** Reads the custom build scripts and the step scripts they run. */
88
+ function readSourcePipeline(root, buildScripts) {
89
+ const pipeline = {
90
+ scripts: [],
91
+ stripHtmlComments: false,
92
+ stripComments: false,
93
+ dropConsole: false,
94
+ };
95
+ const seen = new Set();
96
+ const visit = (rel) => {
97
+ if (seen.has(rel))
98
+ return;
99
+ seen.add(rel);
100
+ const text = read(root, rel);
101
+ if (text === undefined)
102
+ return;
103
+ pipeline.scripts.push(rel);
104
+ const name = path.posix.basename(rel);
105
+ const nonce = nonceOf(text);
106
+ if (nonce && !pipeline.nonce)
107
+ pipeline.nonce = nonce;
108
+ if (nonce && /<!--\(\?!#\)/.test(text))
109
+ pipeline.stripHtmlComments = true;
110
+ if (/obfuscat/i.test(name) && !pipeline.obfuscate)
111
+ Object.assign(pipeline, obfuscateSettings(text));
112
+ if (/strip-?comments/i.test(name))
113
+ pipeline.stripComments = true;
114
+ if (/drop_console|pure_funcs|dropConsole/.test(text))
115
+ pipeline.dropConsole = true;
116
+ const tz = /\btimeZone\s*:\s*['"`]([A-Za-z_]+\/[A-Za-z_+-]+)['"`]/.exec(text)?.[1];
117
+ if (tz && !pipeline.timezone)
118
+ pipeline.timezone = tz;
119
+ for (const called of calledScripts(text))
120
+ visit(called);
121
+ // Local helpers it requires (build-info, timestamp, …): read for the stamp time zone.
122
+ for (const m of text.matchAll(/\brequire\(\s*['"](\.{1,2}\/[\w./-]+)['"]\s*\)/g)) {
123
+ const dep = path.posix.normalize(path.posix.join(path.posix.dirname(rel), m[1]));
124
+ visit(/\.(c|m)?js$/.test(dep) ? dep : `${dep}.js`);
125
+ }
126
+ };
127
+ for (const s of buildScripts)
128
+ visit(s);
129
+ pipeline.scripts.sort();
130
+ return pipeline;
131
+ }
132
+ exports.readSourcePipeline = readSourcePipeline;
133
+ //# sourceMappingURL=pipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../../../../src/generators/adopt/pipeline.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAiC7B,+GAA+G;AAC/G,MAAM,aAAa,GAAwD;IACzE,KAAK,EAAE;QACL,oBAAoB,EAAE,GAAG;QACzB,wBAAwB,EAAE,SAAS;QACnC,wBAAwB,EAAE,CAAC;KAC5B;IACD,MAAM,EAAE;QACN,oBAAoB,EAAE,IAAI;QAC1B,wBAAwB,EAAE,aAAa;QACvC,wBAAwB,EAAE,CAAC;KAC5B;CACF,CAAC;AAEF,mGAAmG;AACnG,SAAS,WAAW,CAAC,KAAa,EAAE,GAAW;IAC7C,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC,MAAM,GAAG,0DAA0D,CAAC,CAAC,IAAI,CAC5F,KAAK,CACN,CAAC;IACF,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACzB,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CA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AAM,CAAC,IAAI,YAAY;QAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IACvC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IACxB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAlCD,gDAkCC"}
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "id": "adopt",
5
+ "title": "Adopt Apps",
6
+ "description": "Move the Angular apps of this workspace that build without the plugin to its release target, in place: release target (base hrefs and post-build steps read from the workspace's own build script), environments/<app>/htaccess.<env>, env encryption settings, build:<app>:<env> npm scripts. Old scripts are kept.",
7
+ "type": "object",
8
+ "properties": {
9
+ "projects": {
10
+ "type": "array",
11
+ "items": { "type": "string" },
12
+ "description": "Apps to adopt (default: every Angular app without a release target)."
13
+ },
14
+ "scripts": {
15
+ "type": "boolean",
16
+ "description": "Point the apps' build:<app>:<env> npm scripts at nx run <app>:release:<env>.",
17
+ "default": true
18
+ },
19
+ "removeOldScripts": {
20
+ "type": "boolean",
21
+ "description": "Delete the old build pipeline scripts nothing uses any more (package.json, project.json, CI and git hooks are checked).",
22
+ "default": false
23
+ }
24
+ },
25
+ "required": []
26
+ }
@@ -256,7 +256,7 @@ function migrateNxWorkspace(tree, ctx) {
256
256
  releaseAdded = releases.length > 0;
257
257
  // Only the release target this run added; a source's own release target stays as it was.
258
258
  if (releases.length > 0)
259
- shapeReleaseTarget(targets, p, buildScripts, notes);
259
+ (0, build_scripts_1.shapeReleaseTarget)(targets, p.source.name, buildScripts, notes);
260
260
  const main = mainOf(targets);
261
261
  if (main)
262
262
  mains.push(main);
@@ -842,52 +842,6 @@ const mainOf = (targets) => {
842
842
  const main = (0, workspace_source_1.objectField)(targets, 'build')['options']?.['main'];
843
843
  return typeof main === 'string' ? main : undefined;
844
844
  };
845
- /**
846
- * The release target of a migrated app: the env folder its fileReplacements use
847
- * (environments/<x>/…), and base hrefs from the source's build scripts.
848
- */
849
- function shapeReleaseTarget(targets, p, scripts, notes) {
850
- const release = targets['release'];
851
- if (!(0, workspace_source_1.isObject)(release) || !(0, workspace_source_1.isObject)(release['options']))
852
- return;
853
- const options = release['options'];
854
- const envProject = envFolderOf((0, workspace_source_1.objectField)(targets, 'build'));
855
- if (envProject && envProject !== options['envProject'])
856
- options['envProject'] = envProject;
857
- const hrefs = scripts.baseHrefs.get(p.source.name);
858
- if (!hrefs)
859
- return;
860
- const configurations = (0, workspace_source_1.isObject)(release['configurations'])
861
- ? release['configurations']
862
- : {};
863
- const applied = [];
864
- for (const [name, config] of Object.entries(configurations)) {
865
- const href = hrefs[name] ?? hrefs['*'];
866
- if (!href || href === '/' || !(0, workspace_source_1.isObject)(config))
867
- continue;
868
- config['baseHref'] = href;
869
- applied.push(`${name}: ${href}`);
870
- }
871
- if (applied.length > 0) {
872
- notes.push(`release target base hrefs from the source build scripts: ${applied.join(', ')}`);
873
- }
874
- }
875
- /** "environments/<x>/environment.prod.ts" in the build's fileReplacements → "<x>". */
876
- function envFolderOf(build) {
877
- const sets = [build['options'], ...Object.values((0, workspace_source_1.objectField)(build, 'configurations'))];
878
- for (const set of sets) {
879
- const replacements = (0, workspace_source_1.isObject)(set) ? set['fileReplacements'] : undefined;
880
- if (!Array.isArray(replacements))
881
- continue;
882
- for (const r of replacements) {
883
- const w = (0, workspace_source_1.isObject)(r) ? r['with'] ?? r['replaceWith'] : undefined;
884
- const m = typeof w === 'string' ? /^(?:\.\/)?environments\/([^/]+)\/[^/]+$/.exec(w) : null;
885
- if (m)
886
- return m[1];
887
- }
888
- }
889
- return undefined;
890
- }
891
845
  const scriptContext = (plan) => ({
892
846
  renames: plan.renames,
893
847
  all: new Set(plan.all.map((p) => p.name)),