@angular-architects/native-federation 18.2.0 → 18.2.2
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/config.js +5 -0
- package/config.js.map +1 -0
- package/package.json +4 -3
- package/src/builders/build/builder.d.ts +5 -0
- package/src/builders/build/builder.js +255 -0
- package/src/builders/build/builder.js.map +1 -0
- package/src/config.d.ts +2 -0
- package/src/config.js +10 -0
- package/src/config.js.map +1 -0
- package/src/executors/build/executor.d.ts +4 -0
- package/src/executors/build/executor.js +13 -0
- package/src/executors/build/executor.js.map +1 -0
- package/src/generators/native-federation/generator.d.ts +3 -0
- package/src/generators/native-federation/generator.js +44 -0
- package/src/generators/native-federation/generator.js.map +1 -0
- package/src/index.js +1 -0
- package/src/index.js.map +1 -0
- package/src/patch-angular-build.d.ts +1 -0
- package/src/patch-angular-build.js +7 -0
- package/src/patch-angular-build.js.map +1 -0
- package/src/plugin/dev-externals-mixin.d.ts +1 -0
- package/src/plugin/dev-externals-mixin.js +30 -0
- package/src/plugin/dev-externals-mixin.js.map +1 -0
- package/src/plugin/externals-skip-list.d.ts +2 -0
- package/src/plugin/externals-skip-list.js +9 -0
- package/src/plugin/externals-skip-list.js.map +1 -0
- package/src/plugin/index.d.ts +2 -0
- package/src/plugin/index.js +107 -0
- package/src/plugin/index.js.map +1 -0
- package/src/schematics/appbuilder/schematic.d.ts +4 -0
- package/src/schematics/appbuilder/schematic.js +95 -0
- package/src/schematics/appbuilder/schematic.js.map +1 -0
- package/src/schematics/init/schematic.d.ts +6 -0
- package/src/schematics/init/schematic.js +316 -0
- package/src/schematics/init/schematic.js.map +1 -0
- package/src/schematics/remove/schematic.d.ts +4 -0
- package/src/schematics/remove/schematic.js +119 -0
- package/src/schematics/remove/schematic.js.map +1 -0
- package/src/schematics/update18/schematic.d.ts +2 -0
- package/src/schematics/update18/schematic.js +14 -0
- package/src/schematics/update18/schematic.js.map +1 -0
- package/src/utils/angular-esbuild-adapter.d.ts +9 -0
- package/src/utils/angular-esbuild-adapter.js +274 -0
- package/src/utils/angular-esbuild-adapter.js.map +1 -0
- package/src/utils/create-compiler-options.d.ts +4 -0
- package/src/utils/create-compiler-options.js +45 -0
- package/src/utils/create-compiler-options.js.map +1 -0
- package/src/utils/dev-server.d.ts +7 -0
- package/src/utils/dev-server.js +94 -0
- package/src/utils/dev-server.js.map +1 -0
- package/src/utils/event-sorce.d.ts +9 -0
- package/src/utils/event-sorce.js +20 -0
- package/src/utils/event-sorce.js.map +1 -0
- package/src/utils/mem-resuts.d.ts +29 -0
- package/src/utils/mem-resuts.js +58 -0
- package/src/utils/mem-resuts.js.map +1 -0
- package/src/utils/patch-angular-build.d.ts +3 -0
- package/src/utils/patch-angular-build.js +36 -0
- package/src/utils/patch-angular-build.js.map +1 -0
- package/src/utils/rebuild-events.d.ts +7 -0
- package/src/utils/rebuild-events.js +11 -0
- package/src/utils/rebuild-events.js.map +1 -0
- package/src/utils/shared-mappings-plugin.d.ts +3 -0
- package/src/utils/shared-mappings-plugin.js +31 -0
- package/src/utils/shared-mappings-plugin.js.map +1 -0
- package/src/utils/updateIndexHtml.d.ts +4 -0
- package/src/utils/updateIndexHtml.js +34 -0
- package/src/utils/updateIndexHtml.js.map +1 -0
- package/.eslintrc.json +0 -25
- package/docs/migrate.md +0 -173
- package/docs/share-faq.md +0 -57
- package/docs/update18.md +0 -19
- package/example.png +0 -0
- package/jest.config.ts +0 -11
- package/post-build.js +0 -10
- package/project.json +0 -80
- package/src/builders/build/builder.ts +0 -370
- package/src/config.ts +0 -6
- package/src/executors/build/executor.spec.ts +0 -11
- package/src/executors/build/executor.ts +0 -12
- package/src/generators/native-federation/generator.spec.ts +0 -20
- package/src/generators/native-federation/generator.ts +0 -76
- package/src/patch-angular-build.ts +0 -8
- package/src/plugin/dev-externals-mixin.ts +0 -34
- package/src/plugin/externals-skip-list.ts +0 -5
- package/src/plugin/index.ts +0 -123
- package/src/schematics/appbuilder/schematic.ts +0 -148
- package/src/schematics/init/schematic.ts +0 -463
- package/src/schematics/remove/schematic.ts +0 -179
- package/src/schematics/update18/schematic.ts +0 -10
- package/src/utils/angular-esbuild-adapter.ts +0 -438
- package/src/utils/create-compiler-options.ts +0 -68
- package/src/utils/dev-server.ts +0 -117
- package/src/utils/event-sorce.ts +0 -18
- package/src/utils/mem-resuts.ts +0 -67
- package/src/utils/patch-angular-build.ts +0 -47
- package/src/utils/rebuild-events.ts +0 -9
- package/src/utils/shared-mappings-plugin.ts +0 -35
- package/src/utils/updateIndexHtml.ts +0 -55
- package/tsconfig.json +0 -23
- package/tsconfig.lib.json +0 -11
- package/tsconfig.spec.json +0 -15
- /package/{config.ts → config.d.ts} +0 -0
- /package/src/{index.ts → index.d.ts} +0 -0
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { Rule, Tree } from '@angular-devkit/schematics';
|
|
2
|
-
|
|
3
|
-
import { MfSchematicSchema } from './schema';
|
|
4
|
-
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
|
|
7
|
-
type NormalizedOptions = {
|
|
8
|
-
polyfills: string;
|
|
9
|
-
projectName: string;
|
|
10
|
-
projectRoot: string;
|
|
11
|
-
projectSourceRoot: string;
|
|
12
|
-
manifestPath: string;
|
|
13
|
-
projectConfig: any;
|
|
14
|
-
main: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default function remove(options: MfSchematicSchema): Rule {
|
|
18
|
-
return async function (tree /*, context*/) {
|
|
19
|
-
const workspaceFileName = getWorkspaceFileName(tree);
|
|
20
|
-
const workspace = JSON.parse(tree.read(workspaceFileName).toString('utf8'));
|
|
21
|
-
|
|
22
|
-
const normalized = normalizeOptions(options, workspace);
|
|
23
|
-
|
|
24
|
-
const { polyfills, projectRoot } = normalized;
|
|
25
|
-
|
|
26
|
-
const bootstrapPath = path.join(projectRoot, 'src/bootstrap.ts');
|
|
27
|
-
const mainPath = path.join(projectRoot, 'src/main.ts');
|
|
28
|
-
|
|
29
|
-
makeMainSync(tree, bootstrapPath, mainPath);
|
|
30
|
-
updatePolyfills(tree, polyfills);
|
|
31
|
-
updateWorkspaceConfig(tree, normalized, workspace, workspaceFileName);
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function makeMainSync(tree, bootstrapPath: string, mainPath: string) {
|
|
36
|
-
if (tree.exists(bootstrapPath) && tree.exists(mainPath)) {
|
|
37
|
-
tree.delete(mainPath);
|
|
38
|
-
tree.rename(bootstrapPath, mainPath);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function updateWorkspaceConfig(
|
|
43
|
-
tree: Tree,
|
|
44
|
-
options: NormalizedOptions,
|
|
45
|
-
workspace: any,
|
|
46
|
-
workspaceFileName: string
|
|
47
|
-
) {
|
|
48
|
-
const { projectConfig } = options;
|
|
49
|
-
|
|
50
|
-
if (!projectConfig?.architect?.build || !projectConfig?.architect?.serve) {
|
|
51
|
-
throw new Error(
|
|
52
|
-
`The project doen't have a build or serve target in angular.json!`
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (projectConfig.architect.esbuild) {
|
|
57
|
-
projectConfig.architect.build = projectConfig.architect.esbuild;
|
|
58
|
-
delete projectConfig.architect.esbuild;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (projectConfig.architect['serve-original']) {
|
|
62
|
-
projectConfig.architect.serve = projectConfig.architect['serve-original'];
|
|
63
|
-
delete projectConfig.architect['serve-original'];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (projectConfig.architect.serve) {
|
|
67
|
-
const conf = projectConfig.architect.serve.configurations;
|
|
68
|
-
conf.production.buildTarget = conf.production.buildTarget.replace(
|
|
69
|
-
':esbuild:',
|
|
70
|
-
':build:'
|
|
71
|
-
);
|
|
72
|
-
conf.development.buildTarget = conf.development.buildTarget.replace(
|
|
73
|
-
':esbuild:',
|
|
74
|
-
':build:'
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
tree.overwrite(workspaceFileName, JSON.stringify(workspace, null, '\t'));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function normalizeOptions(
|
|
82
|
-
options: MfSchematicSchema,
|
|
83
|
-
workspace: any
|
|
84
|
-
): NormalizedOptions {
|
|
85
|
-
if (!options.project) {
|
|
86
|
-
options.project = workspace.defaultProject;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const projects = Object.keys(workspace.projects);
|
|
90
|
-
|
|
91
|
-
if (!options.project && projects.length === 0) {
|
|
92
|
-
throw new Error(
|
|
93
|
-
`No default project found. Please specifiy a project name!`
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (!options.project) {
|
|
98
|
-
console.log(
|
|
99
|
-
'Using first configured project as default project: ' + projects[0]
|
|
100
|
-
);
|
|
101
|
-
options.project = projects[0];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const projectName = options.project;
|
|
105
|
-
const projectConfig = workspace.projects[projectName];
|
|
106
|
-
|
|
107
|
-
if (!projectConfig) {
|
|
108
|
-
throw new Error(`Project ${projectName} not found!`);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const projectRoot: string = projectConfig.root?.replace(/\\/g, '/');
|
|
112
|
-
const projectSourceRoot: string = projectConfig.sourceRoot?.replace(
|
|
113
|
-
/\\/g,
|
|
114
|
-
'/'
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
const manifestPath = path
|
|
118
|
-
.join(projectRoot, 'src/assets/federation.manifest.json')
|
|
119
|
-
.replace(/\\/g, '/');
|
|
120
|
-
|
|
121
|
-
const main = projectConfig.architect.build.options.main;
|
|
122
|
-
|
|
123
|
-
if (!projectConfig.architect.build.options.polyfills) {
|
|
124
|
-
projectConfig.architect.build.options.polyfills = [];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const polyfills = projectConfig.architect.build.options.polyfills;
|
|
128
|
-
return {
|
|
129
|
-
polyfills,
|
|
130
|
-
projectName,
|
|
131
|
-
projectRoot,
|
|
132
|
-
projectSourceRoot,
|
|
133
|
-
manifestPath,
|
|
134
|
-
projectConfig,
|
|
135
|
-
main,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function updatePolyfills(tree, polyfills: any) {
|
|
140
|
-
if (typeof polyfills === 'string') {
|
|
141
|
-
updatePolyfillsFile(tree, polyfills);
|
|
142
|
-
} else {
|
|
143
|
-
updatePolyfillsArray(tree, polyfills);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function updatePolyfillsFile(tree, polyfills: any) {
|
|
148
|
-
let polyfillsContent = tree.readText(polyfills);
|
|
149
|
-
if (polyfillsContent.includes('es-module-shims')) {
|
|
150
|
-
polyfillsContent = polyfillsContent.replace(
|
|
151
|
-
`import 'es-module-shims';`,
|
|
152
|
-
''
|
|
153
|
-
);
|
|
154
|
-
tree.overwrite(polyfills, polyfillsContent);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function updatePolyfillsArray(tree, polyfills: any) {
|
|
159
|
-
const polyfillsConfig = polyfills as string[];
|
|
160
|
-
|
|
161
|
-
const index = polyfillsConfig.findIndex((p) => p === 'es-module-shims');
|
|
162
|
-
if (index === -1) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
polyfillsConfig.splice(index, 1);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function getWorkspaceFileName(tree: Tree): string {
|
|
170
|
-
if (tree.exists('angular.json')) {
|
|
171
|
-
return 'angular.json';
|
|
172
|
-
}
|
|
173
|
-
if (tree.exists('workspace.json')) {
|
|
174
|
-
return 'workspace.json';
|
|
175
|
-
}
|
|
176
|
-
throw new Error(
|
|
177
|
-
"angular.json or workspace.json expected! Did you call this in your project's root?"
|
|
178
|
-
);
|
|
179
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Rule, Tree } from '@angular-devkit/schematics';
|
|
2
|
-
|
|
3
|
-
import { patchAngularBuild, updatePackageJson } from '../init/schematic';
|
|
4
|
-
|
|
5
|
-
export default function update18(): Rule {
|
|
6
|
-
return async function (tree: Tree) {
|
|
7
|
-
updatePackageJson(tree);
|
|
8
|
-
patchAngularBuild(tree);
|
|
9
|
-
};
|
|
10
|
-
}
|
|
@@ -1,438 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BuildAdapter,
|
|
3
|
-
logger,
|
|
4
|
-
MappedPath,
|
|
5
|
-
} from '@softarc/native-federation/build';
|
|
6
|
-
|
|
7
|
-
import * as esbuild from 'esbuild';
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
createCompilerPlugin,
|
|
11
|
-
transformSupportedBrowsersToTargets,
|
|
12
|
-
getSupportedBrowsers,
|
|
13
|
-
} from '@angular/build/private';
|
|
14
|
-
|
|
15
|
-
import { createCompilerPluginOptions } from './create-compiler-options';
|
|
16
|
-
import { BuilderContext } from '@angular-devkit/architect';
|
|
17
|
-
import { findTailwindConfigurationFile } from '@angular-devkit/build-angular/src/utils/tailwind';
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
normalizeOptimization,
|
|
21
|
-
normalizeSourceMaps,
|
|
22
|
-
} from '@angular-devkit/build-angular/src/utils';
|
|
23
|
-
import { createRequire } from 'node:module';
|
|
24
|
-
|
|
25
|
-
import { ApplicationBuilderOptions } from '@angular/build';
|
|
26
|
-
|
|
27
|
-
import * as fs from 'fs';
|
|
28
|
-
import * as path from 'path';
|
|
29
|
-
import { createSharedMappingsPlugin } from './shared-mappings-plugin';
|
|
30
|
-
|
|
31
|
-
import { PluginItem, transformAsync } from '@babel/core';
|
|
32
|
-
import {
|
|
33
|
-
BuildKind,
|
|
34
|
-
BuildResult,
|
|
35
|
-
EntryPoint,
|
|
36
|
-
} from '@softarc/native-federation/build';
|
|
37
|
-
|
|
38
|
-
import { RebuildEvents, RebuildHubs } from './rebuild-events';
|
|
39
|
-
|
|
40
|
-
// const fesmFolderRegExp = /[/\\]fesm\d+[/\\]/;
|
|
41
|
-
|
|
42
|
-
export type MemResultHandler = (
|
|
43
|
-
outfiles: esbuild.OutputFile[],
|
|
44
|
-
outdir?: string
|
|
45
|
-
) => void;
|
|
46
|
-
|
|
47
|
-
let _memResultHandler: MemResultHandler;
|
|
48
|
-
|
|
49
|
-
export function setMemResultHandler(handler: MemResultHandler): void {
|
|
50
|
-
_memResultHandler = handler;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function createAngularBuildAdapter(
|
|
54
|
-
builderOptions: ApplicationBuilderOptions,
|
|
55
|
-
context: BuilderContext,
|
|
56
|
-
rebuildRequested: RebuildEvents = new RebuildHubs()
|
|
57
|
-
): BuildAdapter {
|
|
58
|
-
return async (options) => {
|
|
59
|
-
const {
|
|
60
|
-
entryPoints,
|
|
61
|
-
tsConfigPath,
|
|
62
|
-
external,
|
|
63
|
-
outdir,
|
|
64
|
-
mappedPaths,
|
|
65
|
-
kind,
|
|
66
|
-
watch,
|
|
67
|
-
dev,
|
|
68
|
-
hash,
|
|
69
|
-
} = options;
|
|
70
|
-
|
|
71
|
-
const files = await runEsbuild(
|
|
72
|
-
builderOptions,
|
|
73
|
-
context,
|
|
74
|
-
entryPoints,
|
|
75
|
-
external,
|
|
76
|
-
outdir,
|
|
77
|
-
tsConfigPath,
|
|
78
|
-
mappedPaths,
|
|
79
|
-
watch,
|
|
80
|
-
rebuildRequested,
|
|
81
|
-
dev,
|
|
82
|
-
kind,
|
|
83
|
-
hash
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
if (kind === 'shared-package') {
|
|
87
|
-
const scriptFiles = files.filter(
|
|
88
|
-
(f) => f.endsWith('.js') || f.endsWith('.mjs')
|
|
89
|
-
);
|
|
90
|
-
for (const file of scriptFiles) {
|
|
91
|
-
link(file, dev);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return files.map((fileName) => ({ fileName } as BuildResult));
|
|
96
|
-
|
|
97
|
-
// TODO: Do we still need rollup as esbuilt evolved?
|
|
98
|
-
// if (kind === 'shared-package') {
|
|
99
|
-
// await runRollup(entryPoint, external, outfile);
|
|
100
|
-
// } else {
|
|
101
|
-
|
|
102
|
-
// if (
|
|
103
|
-
// dev &&
|
|
104
|
-
// kind === 'shared-package' &&
|
|
105
|
-
// entryPoint.match(fesmFolderRegExp)
|
|
106
|
-
// ) {
|
|
107
|
-
// fs.copyFileSync(entryPoint, outfile);
|
|
108
|
-
// } else {
|
|
109
|
-
// await runEsbuild(
|
|
110
|
-
// builderOptions,
|
|
111
|
-
// context,
|
|
112
|
-
// entryPoint,
|
|
113
|
-
// external,
|
|
114
|
-
// outfile,
|
|
115
|
-
// tsConfigPath,
|
|
116
|
-
// mappedPaths,
|
|
117
|
-
// watch,
|
|
118
|
-
// rebuildRequested,
|
|
119
|
-
// dev,
|
|
120
|
-
// kind
|
|
121
|
-
// );
|
|
122
|
-
// }
|
|
123
|
-
// if (kind === 'shared-package' && fs.existsSync(outfile)) {
|
|
124
|
-
// await link(outfile, dev);
|
|
125
|
-
// }
|
|
126
|
-
// }
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
async function link(outfile: string, dev: boolean) {
|
|
130
|
-
const code = fs.readFileSync(outfile, 'utf-8');
|
|
131
|
-
|
|
132
|
-
try {
|
|
133
|
-
const linkerEsm = await loadEsmModule<{ default: PluginItem }>(
|
|
134
|
-
'@angular/compiler-cli/linker/babel'
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
const linker = linkerEsm.default;
|
|
138
|
-
|
|
139
|
-
const result = await transformAsync(code, {
|
|
140
|
-
filename: outfile,
|
|
141
|
-
// inputSourceMap: (useInputSourcemap ? undefined : false) as undefined,
|
|
142
|
-
// sourceMaps: pluginOptions.sourcemap ? 'inline' : false,
|
|
143
|
-
compact: !dev,
|
|
144
|
-
configFile: false,
|
|
145
|
-
babelrc: false,
|
|
146
|
-
minified: !dev,
|
|
147
|
-
browserslistConfigFile: false,
|
|
148
|
-
plugins: [linker],
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
fs.writeFileSync(outfile, result.code, 'utf-8');
|
|
152
|
-
} catch (e) {
|
|
153
|
-
logger.error('error linking');
|
|
154
|
-
|
|
155
|
-
if (fs.existsSync(`${outfile}.error`)) {
|
|
156
|
-
fs.unlinkSync(`${outfile}.error`);
|
|
157
|
-
}
|
|
158
|
-
fs.renameSync(outfile, `${outfile}.error`);
|
|
159
|
-
|
|
160
|
-
throw e;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
async function runEsbuild(
|
|
166
|
-
builderOptions: ApplicationBuilderOptions,
|
|
167
|
-
context: BuilderContext,
|
|
168
|
-
entryPoints: EntryPoint[],
|
|
169
|
-
external: string[],
|
|
170
|
-
outdir: string,
|
|
171
|
-
tsConfigPath: string,
|
|
172
|
-
mappedPaths: MappedPath[],
|
|
173
|
-
watch?: boolean,
|
|
174
|
-
rebuildRequested: RebuildEvents = new RebuildHubs(),
|
|
175
|
-
dev?: boolean,
|
|
176
|
-
kind?: BuildKind,
|
|
177
|
-
hash = false,
|
|
178
|
-
plugins: esbuild.Plugin[] | null = null,
|
|
179
|
-
absWorkingDir: string | undefined = undefined,
|
|
180
|
-
logLevel: esbuild.LogLevel = 'warning'
|
|
181
|
-
) {
|
|
182
|
-
const projectRoot = path.dirname(tsConfigPath);
|
|
183
|
-
const browsers = getSupportedBrowsers(projectRoot, context.logger as any);
|
|
184
|
-
const target = transformSupportedBrowsersToTargets(browsers);
|
|
185
|
-
|
|
186
|
-
const workspaceRoot = context.workspaceRoot;
|
|
187
|
-
|
|
188
|
-
const optimizationOptions = normalizeOptimization(
|
|
189
|
-
builderOptions.optimization
|
|
190
|
-
);
|
|
191
|
-
const sourcemapOptions = normalizeSourceMaps(builderOptions.sourceMap);
|
|
192
|
-
const tailwindConfigurationPath = await findTailwindConfigurationFile(
|
|
193
|
-
workspaceRoot,
|
|
194
|
-
projectRoot
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
const fullProjectRoot = path.join(workspaceRoot, projectRoot);
|
|
198
|
-
const resolver = createRequire(fullProjectRoot + '/');
|
|
199
|
-
|
|
200
|
-
const tailwindConfiguration = tailwindConfigurationPath
|
|
201
|
-
? {
|
|
202
|
-
file: tailwindConfigurationPath,
|
|
203
|
-
package: resolver.resolve('tailwindcss'),
|
|
204
|
-
}
|
|
205
|
-
: undefined;
|
|
206
|
-
|
|
207
|
-
const outputNames = {
|
|
208
|
-
bundles: '[name]',
|
|
209
|
-
media: 'media/[name]',
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
let fileReplacements: Record<string, string> | undefined;
|
|
213
|
-
if (builderOptions.fileReplacements) {
|
|
214
|
-
for (const replacement of builderOptions.fileReplacements) {
|
|
215
|
-
fileReplacements ??= {};
|
|
216
|
-
fileReplacements[path.join(workspaceRoot, replacement.replace)] =
|
|
217
|
-
path.join(workspaceRoot, replacement.with);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
tsConfigPath = createTsConfigForFederation(
|
|
222
|
-
workspaceRoot,
|
|
223
|
-
tsConfigPath,
|
|
224
|
-
entryPoints
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
const pluginOptions = createCompilerPluginOptions(
|
|
228
|
-
{
|
|
229
|
-
workspaceRoot,
|
|
230
|
-
optimizationOptions,
|
|
231
|
-
sourcemapOptions,
|
|
232
|
-
tsconfig: tsConfigPath,
|
|
233
|
-
outputNames,
|
|
234
|
-
fileReplacements,
|
|
235
|
-
externalDependencies: external,
|
|
236
|
-
preserveSymlinks: builderOptions.preserveSymlinks,
|
|
237
|
-
stylePreprocessorOptions: builderOptions.stylePreprocessorOptions,
|
|
238
|
-
advancedOptimizations: !dev,
|
|
239
|
-
inlineStyleLanguage: builderOptions.inlineStyleLanguage,
|
|
240
|
-
jit: false,
|
|
241
|
-
tailwindConfiguration,
|
|
242
|
-
} as any,
|
|
243
|
-
target,
|
|
244
|
-
undefined
|
|
245
|
-
);
|
|
246
|
-
|
|
247
|
-
pluginOptions.styleOptions.externalDependencies = [];
|
|
248
|
-
|
|
249
|
-
const config: esbuild.BuildOptions = {
|
|
250
|
-
entryPoints: entryPoints.map((ep) => ({
|
|
251
|
-
in: ep.fileName,
|
|
252
|
-
out: path.parse(ep.outName).name,
|
|
253
|
-
})),
|
|
254
|
-
outdir,
|
|
255
|
-
entryNames: hash ? '[name]-[hash]' : '[name]',
|
|
256
|
-
write: false,
|
|
257
|
-
absWorkingDir,
|
|
258
|
-
external,
|
|
259
|
-
logLevel,
|
|
260
|
-
bundle: true,
|
|
261
|
-
sourcemap: dev,
|
|
262
|
-
minify: !dev,
|
|
263
|
-
supported: {
|
|
264
|
-
'async-await': false,
|
|
265
|
-
'object-rest-spread': false,
|
|
266
|
-
},
|
|
267
|
-
splitting: kind === 'mapping-or-exposed',
|
|
268
|
-
platform: 'browser',
|
|
269
|
-
format: 'esm',
|
|
270
|
-
target: ['esnext'],
|
|
271
|
-
logLimit: kind === 'shared-package' ? 1 : 0,
|
|
272
|
-
plugins: plugins || [
|
|
273
|
-
createCompilerPlugin(
|
|
274
|
-
pluginOptions.pluginOptions,
|
|
275
|
-
pluginOptions.styleOptions
|
|
276
|
-
|
|
277
|
-
// TODO: Once available, use helper functions
|
|
278
|
-
// for creating these config objects:
|
|
279
|
-
// @angular_devkit/build_angular/src/tools/esbuild/compiler-plugin-options.ts
|
|
280
|
-
// {
|
|
281
|
-
// jit: false,
|
|
282
|
-
// sourcemap: dev,
|
|
283
|
-
// tsconfig: tsConfigPath,
|
|
284
|
-
// advancedOptimizations: !dev,
|
|
285
|
-
// thirdPartySourcemaps: false,
|
|
286
|
-
// },
|
|
287
|
-
// {
|
|
288
|
-
// optimization: !dev,
|
|
289
|
-
// sourcemap: dev ? 'inline' : false,
|
|
290
|
-
// workspaceRoot: __dirname,
|
|
291
|
-
// inlineStyleLanguage: builderOptions.inlineStyleLanguage,
|
|
292
|
-
// // browsers: browsers,
|
|
293
|
-
|
|
294
|
-
// target: target,
|
|
295
|
-
// }
|
|
296
|
-
),
|
|
297
|
-
...(mappedPaths && mappedPaths.length > 0
|
|
298
|
-
? [createSharedMappingsPlugin(mappedPaths)]
|
|
299
|
-
: []),
|
|
300
|
-
],
|
|
301
|
-
define: {
|
|
302
|
-
...(!dev ? { ngDevMode: 'false' } : {}),
|
|
303
|
-
ngJitMode: 'false',
|
|
304
|
-
},
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
const ctx = await esbuild.context(config);
|
|
308
|
-
const result = await ctx.rebuild();
|
|
309
|
-
|
|
310
|
-
const memOnly = dev && kind === 'mapping-or-exposed' && !!_memResultHandler;
|
|
311
|
-
|
|
312
|
-
const writtenFiles = writeResult(result, outdir, memOnly);
|
|
313
|
-
|
|
314
|
-
if (watch) {
|
|
315
|
-
registerForRebuilds(
|
|
316
|
-
kind,
|
|
317
|
-
rebuildRequested,
|
|
318
|
-
ctx,
|
|
319
|
-
entryPoints,
|
|
320
|
-
outdir,
|
|
321
|
-
hash,
|
|
322
|
-
memOnly
|
|
323
|
-
);
|
|
324
|
-
} else {
|
|
325
|
-
ctx.dispose();
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
// cleanUpTsConfigForFederation(tsConfigPath);
|
|
329
|
-
|
|
330
|
-
return writtenFiles;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// function cleanUpTsConfigForFederation(tsConfigPath: string) {
|
|
334
|
-
// if (tsConfigPath.includes('.federation.')) {
|
|
335
|
-
// fs.unlinkSync(tsConfigPath);
|
|
336
|
-
// }
|
|
337
|
-
// }
|
|
338
|
-
|
|
339
|
-
function createTsConfigForFederation(
|
|
340
|
-
workspaceRoot: string,
|
|
341
|
-
tsConfigPath: string,
|
|
342
|
-
entryPoints: EntryPoint[]
|
|
343
|
-
) {
|
|
344
|
-
const fullTsConfigPath = path.join(workspaceRoot, tsConfigPath);
|
|
345
|
-
const tsconfigDir = path.dirname(fullTsConfigPath);
|
|
346
|
-
|
|
347
|
-
const filtered = entryPoints
|
|
348
|
-
.filter(
|
|
349
|
-
(ep) =>
|
|
350
|
-
!ep.fileName.includes('/node_modules/') && !ep.fileName.startsWith('.')
|
|
351
|
-
)
|
|
352
|
-
.map((ep) => path.relative(tsconfigDir, ep.fileName).replace(/\\\\/g, '/'));
|
|
353
|
-
|
|
354
|
-
const tsconfigAsString = fs.readFileSync(fullTsConfigPath, 'utf-8');
|
|
355
|
-
const tsconfigWithoutComments = tsconfigAsString.replace(
|
|
356
|
-
/\/\*.+?\*\/|\/\/.*(?=[\n\r])/g,
|
|
357
|
-
''
|
|
358
|
-
);
|
|
359
|
-
const tsconfig = JSON.parse(tsconfigWithoutComments);
|
|
360
|
-
|
|
361
|
-
if (!tsconfig.include) {
|
|
362
|
-
tsconfig.include = [];
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
for (const ep of filtered) {
|
|
366
|
-
if (!tsconfig.include.includes(ep)) {
|
|
367
|
-
tsconfig.include.push(ep);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
const content = JSON.stringify(tsconfig, null, 2);
|
|
372
|
-
|
|
373
|
-
const tsconfigFedPath = path.join(tsconfigDir, 'tsconfig.federation.json');
|
|
374
|
-
|
|
375
|
-
if (!doesFileExist(tsconfigFedPath, content)) {
|
|
376
|
-
fs.writeFileSync(tsconfigFedPath, JSON.stringify(tsconfig, null, 2));
|
|
377
|
-
}
|
|
378
|
-
tsConfigPath = tsconfigFedPath;
|
|
379
|
-
return tsConfigPath;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function doesFileExist(path: string, content: string): boolean {
|
|
383
|
-
if (!fs.existsSync(path)) {
|
|
384
|
-
return false;
|
|
385
|
-
}
|
|
386
|
-
const currentContent = fs.readFileSync(path, 'utf-8');
|
|
387
|
-
return currentContent === content;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
function writeResult(
|
|
391
|
-
result: esbuild.BuildResult<esbuild.BuildOptions>,
|
|
392
|
-
outdir: string,
|
|
393
|
-
memOnly: boolean
|
|
394
|
-
) {
|
|
395
|
-
const writtenFiles: string[] = [];
|
|
396
|
-
|
|
397
|
-
if (memOnly) {
|
|
398
|
-
_memResultHandler(result.outputFiles, outdir);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
for (const outFile of result.outputFiles) {
|
|
402
|
-
const fileName = path.basename(outFile.path);
|
|
403
|
-
const filePath = path.join(outdir, fileName);
|
|
404
|
-
if (!memOnly) {
|
|
405
|
-
fs.writeFileSync(filePath, outFile.text);
|
|
406
|
-
}
|
|
407
|
-
writtenFiles.push(filePath);
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
if (!memOnly) {
|
|
411
|
-
// for (const asset of result.outputFiles)
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return writtenFiles;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
function registerForRebuilds(
|
|
418
|
-
kind: BuildKind,
|
|
419
|
-
rebuildRequested: RebuildEvents,
|
|
420
|
-
ctx: esbuild.BuildContext<esbuild.BuildOptions>,
|
|
421
|
-
entryPoints: EntryPoint[],
|
|
422
|
-
outdir: string,
|
|
423
|
-
hash: boolean,
|
|
424
|
-
memOnly: boolean
|
|
425
|
-
) {
|
|
426
|
-
if (kind !== 'shared-package') {
|
|
427
|
-
rebuildRequested.rebuild.register(async () => {
|
|
428
|
-
const result = await ctx.rebuild();
|
|
429
|
-
writeResult(result, outdir, memOnly);
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
export function loadEsmModule<T>(modulePath: string | URL): Promise<T> {
|
|
435
|
-
return new Function('modulePath', `return import(modulePath);`)(
|
|
436
|
-
modulePath
|
|
437
|
-
) as Promise<T>;
|
|
438
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// Taken from https://github.com/angular/angular-cli/blob/main/packages/angular/build/src/tools/esbuild/compiler-plugin-options.ts
|
|
2
|
-
// Currently, this type cannot be accessed from the outside
|
|
3
|
-
|
|
4
|
-
export function createCompilerPluginOptions(
|
|
5
|
-
options: any,
|
|
6
|
-
target: string[],
|
|
7
|
-
sourceFileCache?: any
|
|
8
|
-
): {
|
|
9
|
-
pluginOptions: any[0];
|
|
10
|
-
styleOptions: any[1];
|
|
11
|
-
} {
|
|
12
|
-
const {
|
|
13
|
-
workspaceRoot,
|
|
14
|
-
optimizationOptions,
|
|
15
|
-
sourcemapOptions,
|
|
16
|
-
tsconfig,
|
|
17
|
-
outputNames,
|
|
18
|
-
fileReplacements,
|
|
19
|
-
externalDependencies,
|
|
20
|
-
preserveSymlinks,
|
|
21
|
-
stylePreprocessorOptions,
|
|
22
|
-
advancedOptimizations,
|
|
23
|
-
inlineStyleLanguage,
|
|
24
|
-
jit,
|
|
25
|
-
cacheOptions,
|
|
26
|
-
tailwindConfiguration,
|
|
27
|
-
postcssConfiguration,
|
|
28
|
-
publicPath,
|
|
29
|
-
} = options;
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
// JS/TS options
|
|
33
|
-
pluginOptions: {
|
|
34
|
-
sourcemap:
|
|
35
|
-
!!sourcemapOptions.scripts &&
|
|
36
|
-
(sourcemapOptions.hidden ? 'external' : true),
|
|
37
|
-
thirdPartySourcemaps: sourcemapOptions.vendor,
|
|
38
|
-
tsconfig,
|
|
39
|
-
jit,
|
|
40
|
-
advancedOptimizations,
|
|
41
|
-
fileReplacements,
|
|
42
|
-
sourceFileCache,
|
|
43
|
-
loadResultCache: sourceFileCache?.loadResultCache,
|
|
44
|
-
incremental: !!options.watch,
|
|
45
|
-
},
|
|
46
|
-
// Component stylesheet options
|
|
47
|
-
styleOptions: {
|
|
48
|
-
workspaceRoot,
|
|
49
|
-
inlineFonts: !!optimizationOptions.fonts.inline,
|
|
50
|
-
optimization: !!optimizationOptions.styles.minify,
|
|
51
|
-
sourcemap:
|
|
52
|
-
// Hidden component stylesheet sourcemaps are inaccessible which is effectively
|
|
53
|
-
// the same as being disabled. Disabling has the advantage of avoiding the overhead
|
|
54
|
-
// of sourcemap processing.
|
|
55
|
-
sourcemapOptions.styles && !sourcemapOptions.hidden ? 'linked' : false,
|
|
56
|
-
outputNames,
|
|
57
|
-
includePaths: stylePreprocessorOptions?.includePaths,
|
|
58
|
-
externalDependencies,
|
|
59
|
-
target,
|
|
60
|
-
inlineStyleLanguage,
|
|
61
|
-
preserveSymlinks,
|
|
62
|
-
tailwindConfiguration,
|
|
63
|
-
postcssConfiguration,
|
|
64
|
-
cacheOptions,
|
|
65
|
-
publicPath,
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
}
|