@simplysm/sd-cli 11.0.9 → 11.0.12

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 (61) hide show
  1. package/dist/build-cluster.js +25 -36
  2. package/dist/build-cluster.js.map +1 -1
  3. package/dist/build-tools/SdCliCordova.js +5 -5
  4. package/dist/build-tools/SdCliCordova.js.map +1 -1
  5. package/dist/build-tools/SdCliNgRoutesFileGenerator.d.ts +4 -0
  6. package/dist/build-tools/SdCliNgRoutesFileGenerator.js +64 -0
  7. package/dist/build-tools/SdCliNgRoutesFileGenerator.js.map +1 -0
  8. package/dist/build-tools/SdLinter.js +8 -1
  9. package/dist/build-tools/SdLinter.js.map +1 -1
  10. package/dist/build-tools/SdNgBundler.d.ts +18 -8
  11. package/dist/build-tools/SdNgBundler.js +286 -213
  12. package/dist/build-tools/SdNgBundler.js.map +1 -1
  13. package/dist/build-tools/SdTsBundler.d.ts +6 -5
  14. package/dist/build-tools/SdTsBundler.js +78 -80
  15. package/dist/build-tools/SdTsBundler.js.map +1 -1
  16. package/dist/build-tools/SdTsCompiler.d.ts +1 -0
  17. package/dist/build-tools/SdTsCompiler.js +5 -1
  18. package/dist/build-tools/SdTsCompiler.js.map +1 -1
  19. package/dist/builders/SdCliClientBuilder.js +51 -36
  20. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  21. package/dist/builders/SdCliServerBuilder.d.ts +6 -2
  22. package/dist/builders/SdCliServerBuilder.js +107 -141
  23. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  24. package/dist/builders/SdCliTsLibBuilder.d.ts +6 -3
  25. package/dist/builders/SdCliTsLibBuilder.js +42 -45
  26. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  27. package/dist/commons.d.ts +0 -2
  28. package/dist/entry/SdCliElectron.js +3 -3
  29. package/dist/entry/SdCliElectron.js.map +1 -1
  30. package/dist/entry/SdCliProject.d.ts +0 -3
  31. package/dist/entry/SdCliProject.js +10 -33
  32. package/dist/entry/SdCliProject.js.map +1 -1
  33. package/dist/index.d.ts +3 -0
  34. package/dist/index.js +3 -0
  35. package/dist/index.js.map +1 -1
  36. package/dist/sd-cli.js +3 -21
  37. package/dist/sd-cli.js.map +1 -1
  38. package/dist/utils/SdMemoryLoadResultCache.d.ts +9 -0
  39. package/dist/utils/SdMemoryLoadResultCache.js +39 -0
  40. package/dist/utils/SdMemoryLoadResultCache.js.map +1 -0
  41. package/dist/utils/SdSourceFileCache.d.ts +5 -0
  42. package/dist/utils/SdSourceFileCache.js +9 -0
  43. package/dist/utils/SdSourceFileCache.js.map +1 -0
  44. package/package.json +17 -17
  45. package/src/build-cluster.ts +26 -36
  46. package/src/build-tools/SdCliCordova.ts +5 -5
  47. package/src/build-tools/SdCliNgRoutesFileGenerator.ts +80 -0
  48. package/src/build-tools/SdLinter.ts +12 -1
  49. package/src/build-tools/SdNgBundler.ts +431 -333
  50. package/src/build-tools/SdTsBundler.ts +86 -86
  51. package/src/build-tools/SdTsCompiler.ts +6 -1
  52. package/src/builders/SdCliClientBuilder.ts +62 -43
  53. package/src/builders/SdCliServerBuilder.ts +64 -63
  54. package/src/builders/SdCliTsLibBuilder.ts +58 -50
  55. package/src/commons.ts +1 -2
  56. package/src/entry/SdCliElectron.ts +3 -3
  57. package/src/entry/SdCliProject.ts +12 -41
  58. package/src/index.ts +3 -0
  59. package/src/sd-cli.ts +3 -21
  60. package/src/utils/SdMemoryLoadResultCache.ts +44 -0
  61. package/src/utils/SdSourceFileCache.ts +6 -0
@@ -1,26 +1,39 @@
1
- import { createCompilerPlugin, SourceFileCache } from "@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin";
1
+ import { createCompilerPlugin } from "@angular-devkit/build-angular/src/tools/esbuild/angular/compiler-plugin";
2
2
  import path from "path";
3
- import { CrossOrigin } from "@angular-devkit/build-angular/src/builders/application/schema";
4
3
  import { BundlerContext } from "@angular-devkit/build-angular/src/tools/esbuild/bundler-context";
5
- import { createCompilerPluginOptions } from "@angular-devkit/build-angular/src/tools/esbuild/compiler-plugin-options";
6
- import { FsUtil, Logger, PathUtil } from "@simplysm/sd-core-node";
4
+ import { FsUtil, PathUtil } from "@simplysm/sd-core-node";
7
5
  import { fileURLToPath } from "url";
8
6
  import { createVirtualModulePlugin } from "@angular-devkit/build-angular/src/tools/esbuild/virtual-module-plugin";
9
7
  import { createSourcemapIgnorelistPlugin } from "@angular-devkit/build-angular/src/tools/esbuild/sourcemap-ignorelist-plugin";
10
8
  import nodeStdLibBrowser from "node-stdlib-browser";
11
9
  import nodeStdLibBrowserPlugin from "node-stdlib-browser/helpers/esbuild/plugin";
12
10
  import { ExecutionResult } from "@angular-devkit/build-angular/src/tools/esbuild/bundler-execution-result";
13
- import { generateIndexHtml } from "@angular-devkit/build-angular/src/tools/esbuild/index-html-generator";
14
11
  import { copyAssets } from "@angular-devkit/build-angular/src/utils/copy-assets";
15
12
  import { extractLicenses } from "@angular-devkit/build-angular/src/tools/esbuild/license-extractor";
16
13
  import { augmentAppWithServiceWorkerEsbuild } from "@angular-devkit/build-angular/src/utils/service-worker";
17
- import { createGlobalStylesBundleOptions } from "@angular-devkit/build-angular/src/tools/esbuild/global-styles";
14
+ import browserslist from "browserslist";
15
+ import { transformSupportedBrowsersToTargets } from "@angular-devkit/build-angular/src/tools/esbuild/utils";
16
+ import { createCssResourcePlugin } from "@angular-devkit/build-angular/src/tools/esbuild/stylesheets/css-resource-plugin";
17
+ import { CssStylesheetLanguage } from "@angular-devkit/build-angular/src/tools/esbuild/stylesheets/css-language";
18
+ import { SassStylesheetLanguage } from "@angular-devkit/build-angular/src/tools/esbuild/stylesheets/sass-language";
19
+ import { StylesheetPluginFactory } from "@angular-devkit/build-angular/src/tools/esbuild/stylesheets/stylesheet-plugin-factory";
20
+ import { IndexHtmlGenerator } from "@angular-devkit/build-angular/src/utils/index-file/index-html-generator";
21
+ import { CrossOrigin } from "@angular-devkit/build-angular";
22
+ import { InlineCriticalCssProcessor } from "@angular-devkit/build-angular/src/utils/index-file/inline-critical-css";
23
+ import { SdSourceFileCache } from "../utils/SdSourceFileCache";
18
24
  export class SdNgBundler {
19
- constructor(opt) {
20
- this._logger = Logger.get(["simplysm", "sd-cli", "SdNgEsbuildBuilder"]);
21
- this._sourceFileCache = new SourceFileCache();
25
+ constructor(_opt) {
26
+ this._opt = _opt;
27
+ this._sourceFileCache = new SdSourceFileCache();
22
28
  this._outputCache = new Map();
23
- this._options = this._getOptions(opt);
29
+ this._pkgNpmConf = FsUtil.readJson(path.resolve(this._opt.pkgPath, "package.json"));
30
+ this._mainFilePath = path.resolve(this._opt.pkgPath, "src/main.ts");
31
+ this._tsConfigFilePath = path.resolve(this._opt.pkgPath, "tsconfig.json");
32
+ this._swConfFilePath = path.resolve(this._opt.pkgPath, "ngsw-config.json");
33
+ this._browserTarget = transformSupportedBrowsersToTargets(browserslist("defaults and fully supports es6-module"));
34
+ this._indexHtmlFilePath = path.resolve(this._opt.pkgPath, "src/index.html");
35
+ this._pkgName = path.basename(this._opt.pkgPath);
36
+ this._baseHref = this._opt.builderType === "web" ? `/${this._pkgName}/` : this._opt.dev ? `/${this._pkgName}/${this._opt.builderType}/` : ``;
24
37
  }
25
38
  removeCache(filePaths) {
26
39
  this._sourceFileCache.invalidate(filePaths);
@@ -35,7 +48,7 @@ export class SdNgBundler {
35
48
  const bundlingResult = await BundlerContext.bundleAll(this._contexts);
36
49
  const results = [
37
50
  ...bundlingResult.warnings.map((warn) => ({
38
- filePath: warn.location?.file !== undefined ? path.resolve(this._options.workspaceRoot, warn.location.file) : undefined,
51
+ filePath: warn.location?.file !== undefined ? path.resolve(this._opt.pkgPath, warn.location.file) : undefined,
39
52
  line: warn.location?.line,
40
53
  char: warn.location?.column,
41
54
  code: undefined,
@@ -44,7 +57,7 @@ export class SdNgBundler {
44
57
  type: "build"
45
58
  })),
46
59
  ...bundlingResult.errors?.map((err) => ({
47
- filePath: err.location?.file !== undefined ? path.resolve(this._options.workspaceRoot, err.location.file) : undefined,
60
+ filePath: err.location?.file !== undefined ? path.resolve(this._opt.pkgPath, err.location.file) : undefined,
48
61
  line: err.location?.line,
49
62
  char: err.location?.column !== undefined ? err.location.column + 1 : undefined,
50
63
  code: undefined,
@@ -55,26 +68,26 @@ export class SdNgBundler {
55
68
  ];
56
69
  const watchFilePaths = [
57
70
  ...this._sourceFileCache.keys(),
58
- ...this._sourceFileCache.babelFileCache.keys()
59
- ].map((item) => path.resolve(item));
60
- let affectedSourceFilePaths = watchFilePaths.filter((item) => PathUtil.isChildPath(item, this._options.workspaceRoot));
71
+ ...this._sourceFileCache.babelFileCache.keys(),
72
+ ...this._sourceFileCache.loadResultCache.fileDependencies.keys()
73
+ ].map((item) => path.resolve(item)).distinct();
74
+ let affectedSourceFilePaths = watchFilePaths.filter((item) => PathUtil.isChildPath(item, this._opt.pkgPath));
61
75
  if (bundlingResult.errors) {
62
- return {
63
- filePaths: watchFilePaths,
64
- affectedFilePaths: affectedSourceFilePaths,
65
- results
66
- };
76
+ // TODO: 제대로 deps를 적용해야함.. 코드 분석 필요
77
+ this._depsMap = this._depsMap ?? new Map();
67
78
  }
68
- const depsMap = new Map();
69
- for (const entry of Object.entries(bundlingResult.metafile.inputs)) {
70
- for (const imp of entry[1].imports) {
71
- const deps = depsMap.getOrCreate(path.resolve(this._options.workspaceRoot, imp.path), new Set());
72
- deps.add(path.resolve(this._options.workspaceRoot, entry[0]));
79
+ else {
80
+ this._depsMap = new Map();
81
+ for (const entry of Object.entries(bundlingResult.metafile.inputs)) {
82
+ for (const imp of entry[1].imports) {
83
+ const deps = this._depsMap.getOrCreate(path.resolve(this._opt.pkgPath, imp.path), new Set());
84
+ deps.add(path.resolve(this._opt.pkgPath, entry[0]));
85
+ }
73
86
  }
74
87
  }
75
88
  const searchAffectedFiles = (filePath, prev) => {
76
89
  const result = new Set(prev);
77
- const importerPaths = depsMap.get(filePath);
90
+ const importerPaths = this._depsMap.get(filePath);
78
91
  if (!importerPaths)
79
92
  return result;
80
93
  for (const importerPath of importerPaths) {
@@ -91,48 +104,85 @@ export class SdNgBundler {
91
104
  affectedFilePathSet.add(path.resolve(modFile));
92
105
  affectedFilePathSet.adds(...searchAffectedFiles(path.resolve(modFile)));
93
106
  }
94
- affectedSourceFilePaths = Array.from(affectedFilePathSet.values()).filter((item) => PathUtil.isChildPath(item, this._options.workspaceRoot));
107
+ affectedSourceFilePaths = Array.from(affectedFilePathSet.values()).filter((item) => PathUtil.isChildPath(item, this._opt.pkgPath));
108
+ }
109
+ if (bundlingResult.errors) {
110
+ return {
111
+ filePaths: watchFilePaths,
112
+ affectedFilePaths: affectedSourceFilePaths,
113
+ results
114
+ };
95
115
  }
96
116
  const executionResult = new ExecutionResult(this._contexts, this._sourceFileCache);
97
117
  executionResult.outputFiles.push(...bundlingResult.outputFiles);
118
+ //-- Check commonjs
119
+ // if (!this._opt.dev) {
120
+ // const messages = checkCommonJSModules(bundlingResult.metafile, []);
121
+ // for (const msg of messages) {
122
+ // results.push({
123
+ // filePath: msg.location?.file,
124
+ // line: msg.location?.line,
125
+ // char: msg.location?.column,
126
+ // code: msg.pluginName,
127
+ // severity: "warning",
128
+ // message: msg.text ?? "",
129
+ // type: "build"
130
+ // });
131
+ // }
132
+ // }
98
133
  //-- index
99
- if (this._options.indexHtmlOptions) {
100
- const genIndexHtmlResult = await generateIndexHtml(bundlingResult.initialFiles, executionResult, this._options);
101
- if (genIndexHtmlResult.warnings.length > 0) {
102
- this._logger.warn(...genIndexHtmlResult.warnings);
103
- }
104
- if (genIndexHtmlResult.errors.length > 0) {
105
- this._logger.warn(...genIndexHtmlResult.errors);
106
- }
107
- executionResult.addOutputFile(this._options.indexHtmlOptions.output, genIndexHtmlResult.content);
134
+ const genIndexHtmlResult = await this._genIndexHtmlAsync(bundlingResult.outputFiles, bundlingResult.initialFiles);
135
+ for (const warning of genIndexHtmlResult.warnings) {
136
+ results.push({
137
+ filePath: undefined,
138
+ line: undefined,
139
+ char: undefined,
140
+ code: undefined,
141
+ severity: "warning",
142
+ message: warning,
143
+ type: "build",
144
+ });
108
145
  }
109
- //-- copy assets
110
- if (this._options.assets) {
111
- executionResult.assetFiles.push(...(await copyAssets(this._options.assets, [], this._options.workspaceRoot)));
146
+ for (const error of genIndexHtmlResult.errors) {
147
+ results.push({
148
+ filePath: undefined,
149
+ line: undefined,
150
+ char: undefined,
151
+ code: undefined,
152
+ severity: "error",
153
+ message: error,
154
+ type: "build",
155
+ });
112
156
  }
157
+ executionResult.addOutputFile("index.html", genIndexHtmlResult.content);
158
+ //-- copy assets
159
+ executionResult.assetFiles.push(...(await this._copyAssetsAsync()));
113
160
  //-- extract 3rdpartylicenses
114
- if (this._options.extractLicenses) {
115
- executionResult.addOutputFile('3rdpartylicenses.txt', await extractLicenses(bundlingResult.metafile, this._options.workspaceRoot));
161
+ if (!this._opt.dev) {
162
+ executionResult.addOutputFile('3rdpartylicenses.txt', await extractLicenses(bundlingResult.metafile, this._opt.pkgPath));
116
163
  }
117
164
  //-- service worker
118
- if (this._options.serviceWorker !== undefined) {
165
+ if (FsUtil.exists(this._swConfFilePath)) {
119
166
  try {
120
- const serviceWorkerResult = await augmentAppWithServiceWorkerEsbuild(this._options.workspaceRoot, this._options.serviceWorker, this._options.baseHref ?? '/', executionResult.outputFiles, executionResult.assetFiles);
167
+ const serviceWorkerResult = await this._genServiceWorkerAsync(executionResult.outputFiles, executionResult.assetFiles);
121
168
  executionResult.addOutputFile('ngsw.json', serviceWorkerResult.manifest);
122
169
  executionResult.assetFiles.push(...serviceWorkerResult.assetFiles);
123
170
  }
124
- catch (error) {
125
- this._logger.error(error instanceof Error ? error.message : `${error}`);
126
- return {
127
- filePaths: watchFilePaths,
128
- affectedFilePaths: affectedSourceFilePaths,
129
- results
130
- };
171
+ catch (err) {
172
+ results.push({
173
+ filePath: undefined,
174
+ line: undefined,
175
+ char: undefined,
176
+ code: undefined,
177
+ severity: "error",
178
+ message: err.toString(),
179
+ type: "build",
180
+ });
131
181
  }
132
182
  }
133
183
  //-- write
134
184
  for (const outputFile of executionResult.outputFiles) {
135
- const distFilePath = path.resolve(this._options.outputPath, outputFile.path);
185
+ const distFilePath = path.resolve(this._opt.outputPath, outputFile.path);
136
186
  const prev = this._outputCache.get(distFilePath);
137
187
  if (prev !== Buffer.from(outputFile.contents).toString("base64")) {
138
188
  await FsUtil.writeFileAsync(distFilePath, outputFile.contents);
@@ -143,7 +193,7 @@ export class SdNgBundler {
143
193
  const prev = this._outputCache.get(assetFile.source);
144
194
  const curr = FsUtil.lstat(assetFile.source).mtime.getTime();
145
195
  if (prev !== curr) {
146
- await FsUtil.copyAsync(assetFile.source, path.resolve(this._options.outputPath, assetFile.destination));
196
+ await FsUtil.copyAsync(assetFile.source, path.resolve(this._opt.outputPath, assetFile.destination));
147
197
  this._outputCache.set(assetFile.source, curr);
148
198
  }
149
199
  }
@@ -153,43 +203,114 @@ export class SdNgBundler {
153
203
  results
154
204
  };
155
205
  }
156
- async _getAppContextAsync() {
157
- const esbuildOption = await this._getEsBuildOptionsAsync();
158
- return new BundlerContext(this._options.workspaceRoot, true, esbuildOption);
206
+ async _genIndexHtmlAsync(outputFiles, initialFiles) {
207
+ const readAsset = (filePath) => {
208
+ const relFilePath = path.relative("/", filePath);
209
+ const currFile = outputFiles.find((outputFile) => outputFile.path === relFilePath);
210
+ if (currFile) {
211
+ return Promise.resolve(currFile.text);
212
+ }
213
+ throw new Error(`Output file does not exist: ${relFilePath}`);
214
+ };
215
+ const indexHtmlGenerator = new IndexHtmlGenerator({
216
+ indexPath: this._indexHtmlFilePath,
217
+ entrypoints: [
218
+ ['runtime', true],
219
+ ['polyfills', true],
220
+ ['styles', false],
221
+ ['vendor', true],
222
+ ['main', true],
223
+ ...this._opt.builderType === "cordova" ? [
224
+ ["cordova-entry", true]
225
+ ] : []
226
+ ],
227
+ optimization: {
228
+ scripts: !this._opt.dev,
229
+ fonts: { inline: !this._opt.dev },
230
+ styles: {
231
+ minify: !this._opt.dev,
232
+ inlineCritical: false
233
+ },
234
+ },
235
+ crossOrigin: CrossOrigin.None,
236
+ });
237
+ indexHtmlGenerator.readAsset = readAsset;
238
+ const hints = [];
239
+ if (!this._opt.dev) {
240
+ for (const [key, value] of initialFiles) {
241
+ if (value.entrypoint) {
242
+ continue;
243
+ }
244
+ if (value.type === 'script') {
245
+ hints.push({ url: key, mode: 'modulepreload' });
246
+ }
247
+ else if (value.type === 'style') {
248
+ hints.push({ url: key, mode: 'preload', as: 'style' });
249
+ }
250
+ }
251
+ }
252
+ const transformResult = await indexHtmlGenerator.process({
253
+ baseHref: this._baseHref,
254
+ lang: undefined,
255
+ outputPath: "/",
256
+ files: [...initialFiles].map(([file, record]) => ({
257
+ name: record.name ?? '',
258
+ file,
259
+ extension: path.extname(file),
260
+ })),
261
+ hints,
262
+ });
263
+ if (this._opt.dev) {
264
+ return transformResult;
265
+ }
266
+ else {
267
+ const inlineCriticalCssProcessor = new InlineCriticalCssProcessor({
268
+ minify: false,
269
+ readAsset,
270
+ });
271
+ const { content, errors, warnings } = await inlineCriticalCssProcessor.process(transformResult.content, { outputPath: "/", });
272
+ return {
273
+ warnings: [...transformResult.warnings, ...warnings],
274
+ errors: [...transformResult.errors, ...errors],
275
+ content
276
+ };
277
+ }
159
278
  }
160
- _getStyleContext() {
161
- const esbuildOptions = createGlobalStylesBundleOptions(this._options, [
162
- 'chrome117.0', 'chrome116.0',
163
- 'edge117.0', 'edge116.0',
164
- 'firefox118.0', 'firefox115.0',
165
- 'ios17.0', 'ios16.6',
166
- 'ios16.5', 'ios16.4',
167
- 'ios16.3', 'ios16.2',
168
- 'ios16.1', 'ios16.0',
169
- 'safari17.0', 'safari16.6',
170
- 'safari16.5', 'safari16.4',
171
- 'safari16.3', 'safari16.2',
172
- 'safari16.1', 'safari16.0'
173
- ], true, this._sourceFileCache.loadResultCache);
174
- return new BundlerContext(this._options.workspaceRoot, true, esbuildOptions, () => true);
279
+ async _copyAssetsAsync() {
280
+ return await copyAssets([
281
+ { input: 'src', glob: 'favicon.ico', output: '' },
282
+ { input: 'src', glob: 'manifest.webmanifest', output: '' },
283
+ { input: 'src/assets', glob: '**/*', output: 'assets' },
284
+ ...this._opt.dev && this._opt.cordovaPlatforms ? this._opt.cordovaPlatforms.mapMany((platform) => [
285
+ {
286
+ input: `.cordova/platforms/${platform}/platform_www/plugins`,
287
+ glob: '**/*',
288
+ output: `cordova-${platform}/plugins`
289
+ },
290
+ {
291
+ input: `.cordova/platforms/${platform}/platform_www`,
292
+ glob: 'cordova.js',
293
+ output: `cordova-${platform}`
294
+ },
295
+ {
296
+ input: `.cordova/platforms/${platform}/platform_www`,
297
+ glob: 'cordova_plugins.js',
298
+ output: `cordova-${platform}`
299
+ },
300
+ {
301
+ input: `.cordova/platforms/${platform}/www`,
302
+ glob: 'config.xml',
303
+ output: `cordova-${platform}`
304
+ },
305
+ ]) : []
306
+ ], [], this._opt.pkgPath);
175
307
  }
176
- async _getEsBuildOptionsAsync() {
177
- const pkgNpmConf = FsUtil.readJson(path.resolve(this._options.workspaceRoot, "package.json"));
178
- const { pluginOptions, styleOptions } = createCompilerPluginOptions(this._options, [
179
- 'chrome117.0', 'chrome116.0',
180
- 'edge117.0', 'edge116.0',
181
- 'firefox118.0', 'firefox115.0',
182
- 'ios17.0', 'ios16.6',
183
- 'ios16.5', 'ios16.4',
184
- 'ios16.3', 'ios16.2',
185
- 'ios16.1', 'ios16.0',
186
- 'safari17.0', 'safari16.6',
187
- 'safari16.5', 'safari16.4',
188
- 'safari16.3', 'safari16.2',
189
- 'safari16.1', 'safari16.0'
190
- ], this._sourceFileCache);
191
- return {
192
- absWorkingDir: this._options.workspaceRoot,
308
+ async _genServiceWorkerAsync(outputFiles, assetFiles) {
309
+ return await augmentAppWithServiceWorkerEsbuild(this._opt.pkgPath, this._swConfFilePath, this._baseHref, outputFiles, assetFiles);
310
+ }
311
+ async _getAppContextAsync() {
312
+ return new BundlerContext(this._opt.pkgPath, true, {
313
+ absWorkingDir: this._opt.pkgPath,
193
314
  bundle: true,
194
315
  keepNames: true,
195
316
  format: 'esm',
@@ -197,50 +318,42 @@ export class SdNgBundler {
197
318
  conditions: ['es2020', 'es2015', 'module'],
198
319
  resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
199
320
  metafile: true,
200
- legalComments: this._options.watch ? 'eof' : 'none',
321
+ legalComments: this._opt.dev ? 'eof' : 'none',
201
322
  logLevel: 'silent',
202
- minifyIdentifiers: !this._options.watch,
203
- minifySyntax: !this._options.watch,
204
- minifyWhitespace: !this._options.watch,
323
+ minifyIdentifiers: !this._opt.dev,
324
+ minifySyntax: !this._opt.dev,
325
+ minifyWhitespace: !this._opt.dev,
205
326
  pure: ['forwardRef'],
206
- outdir: this._options.workspaceRoot,
327
+ outdir: this._opt.pkgPath,
207
328
  outExtension: undefined,
208
- sourcemap: this._options.watch,
329
+ sourcemap: this._opt.dev,
209
330
  splitting: true,
210
331
  chunkNames: 'chunk-[hash]',
211
- tsconfig: this._options.tsconfig,
332
+ tsconfig: this._tsConfigFilePath,
212
333
  external: [],
213
334
  write: false,
214
335
  preserveSymlinks: false,
215
336
  define: {
216
- ...!this._options.watch ? { ngDevMode: 'false' } : {},
337
+ ...!this._opt.dev ? { ngDevMode: 'false' } : {},
217
338
  ngJitMode: 'false',
218
339
  global: 'global',
219
340
  process: 'process',
220
341
  Buffer: 'Buffer',
221
- 'process.env.SD_VERSION': JSON.stringify(pkgNpmConf.version),
222
- "process.env.NODE_ENV": JSON.stringify(this._options.watch ? "development" : "production")
342
+ 'process.env.SD_VERSION': JSON.stringify(this._pkgNpmConf.version),
343
+ "process.env.NODE_ENV": JSON.stringify(this._opt.dev ? "development" : "production"),
344
+ ...this._opt.env ? Object.keys(this._opt.env).toObject(key => `process.env.${key}`, key => JSON.stringify(this._opt.env[key])) : {}
223
345
  },
224
346
  platform: 'browser',
225
347
  mainFields: ['es2020', 'es2015', 'browser', 'module', 'main'],
226
348
  entryNames: '[name]',
227
349
  entryPoints: {
228
- ...this._options.entryPoints,
229
- polyfills: 'angular:polyfills'
350
+ main: this._mainFilePath,
351
+ polyfills: 'angular:polyfills',
352
+ ...this._opt.builderType === "cordova" ? {
353
+ "cordova-entry": path.resolve(path.dirname(fileURLToPath(import.meta.url)), `../../lib/cordova-entry.js`)
354
+ } : {}
230
355
  },
231
- target: [
232
- 'chrome117.0', 'chrome116.0',
233
- 'edge117.0', 'edge116.0',
234
- 'firefox118.0', 'firefox115.0',
235
- 'ios17.0', 'ios16.6',
236
- 'ios16.5', 'ios16.4',
237
- 'ios16.3', 'ios16.2',
238
- 'ios16.1', 'ios16.0',
239
- 'safari17.0', 'safari16.6',
240
- 'safari16.5', 'safari16.4',
241
- 'safari16.3', 'safari16.2',
242
- 'safari16.1', 'safari16.0'
243
- ],
356
+ target: this._browserTarget,
244
357
  supported: { 'async-await': false, 'object-rest-spread': false },
245
358
  loader: {
246
359
  ".png": "file",
@@ -273,115 +386,75 @@ export class SdNgBundler {
273
386
  loadContent: () => ({
274
387
  contents: `import "./src/polyfills.ts";`,
275
388
  loader: 'js',
276
- resolveDir: this._options.workspaceRoot
389
+ resolveDir: this._opt.pkgPath
277
390
  })
278
391
  }),
279
392
  createSourcemapIgnorelistPlugin(),
280
- createCompilerPlugin(pluginOptions, styleOptions),
393
+ createCompilerPlugin({
394
+ sourcemap: this._opt.dev,
395
+ thirdPartySourcemaps: false,
396
+ tsconfig: this._tsConfigFilePath,
397
+ jit: false,
398
+ advancedOptimizations: true,
399
+ fileReplacements: undefined,
400
+ sourceFileCache: this._sourceFileCache,
401
+ loadResultCache: this._sourceFileCache.loadResultCache
402
+ }, {
403
+ workspaceRoot: this._opt.pkgPath,
404
+ optimization: !this._opt.dev,
405
+ sourcemap: this._opt.dev ? 'inline' : false,
406
+ outputNames: { bundles: '[name]', media: 'media/[name]' },
407
+ includePaths: [],
408
+ externalDependencies: [],
409
+ target: this._browserTarget,
410
+ inlineStyleLanguage: 'scss',
411
+ preserveSymlinks: false,
412
+ tailwindConfiguration: undefined
413
+ }),
281
414
  nodeStdLibBrowserPlugin(nodeStdLibBrowser)
282
415
  ]
283
- };
416
+ });
284
417
  }
285
- _getOptions(opt) {
286
- const mainFilePath = path.resolve(opt.pkgPath, "src/main.ts");
287
- const tsconfigFilePath = path.resolve(opt.pkgPath, "tsconfig.json");
288
- const indexHtmlFilePath = path.resolve(opt.pkgPath, "src/index.html");
289
- const swFilePath = path.resolve(opt.pkgPath, "ngsw-config.json");
290
- const cacheBasePath = path.resolve(opt.pkgPath, ".cache");
291
- const pkgName = path.basename(opt.pkgPath);
292
- return {
293
- advancedOptimizations: true,
294
- allowedCommonJsDependencies: [],
295
- baseHref: `/${pkgName}/`,
296
- cacheOptions: {
297
- enabled: true,
298
- basePath: cacheBasePath,
299
- path: path.resolve(cacheBasePath, opt.builderType)
300
- },
301
- crossOrigin: CrossOrigin.None,
302
- deleteOutputPath: true,
303
- externalDependencies: [],
304
- extractLicenses: !opt.dev,
305
- inlineStyleLanguage: 'scss',
306
- jit: false,
307
- stats: false,
308
- polyfills: ["./src/polyfills.ts"],
309
- poll: undefined,
310
- progress: true,
311
- externalPackages: opt.dev ? true : undefined,
418
+ _getStyleContext() {
419
+ const browserTarget = transformSupportedBrowsersToTargets(browserslist("defaults and fully supports es6-module"));
420
+ const pluginFactory = new StylesheetPluginFactory({
421
+ sourcemap: this._opt.dev,
422
+ includePaths: []
423
+ }, this._sourceFileCache.loadResultCache);
424
+ return new BundlerContext(this._opt.pkgPath, true, {
425
+ absWorkingDir: this._opt.pkgPath,
426
+ bundle: true,
427
+ entryNames: '[name]',
428
+ assetNames: 'media/[name]',
429
+ logLevel: 'silent',
430
+ minify: !this._opt.dev,
431
+ metafile: true,
432
+ sourcemap: this._opt.dev,
433
+ outdir: this._opt.pkgPath,
434
+ write: false,
435
+ platform: 'browser',
436
+ target: browserTarget,
312
437
  preserveSymlinks: false,
313
- stylePreprocessorOptions: { includePaths: [] },
314
- subresourceIntegrity: false,
315
- serverEntryPoint: undefined,
316
- prerenderOptions: undefined,
317
- appShellOptions: undefined,
318
- ssrOptions: undefined,
319
- verbose: false,
320
- watch: opt.dev,
321
- workspaceRoot: opt.pkgPath,
322
- entryPoints: {
323
- main: mainFilePath,
324
- ...opt.builderType === "cordova" ? {
325
- "cordova-entry": path.resolve(path.dirname(fileURLToPath(import.meta.url)), `../../lib/cordova-entry.js`)
326
- } : {}
327
- },
328
- optimizationOptions: {
329
- scripts: !opt.dev,
330
- styles: { minify: !opt.dev, inlineCritical: !opt.dev },
331
- fonts: { inline: !opt.dev }
332
- },
333
- outputPath: opt.outputPath,
334
- outExtension: undefined,
335
- sourcemapOptions: { vendor: false, hidden: false, scripts: opt.dev, styles: opt.dev },
336
- tsconfig: tsconfigFilePath,
337
- projectRoot: opt.pkgPath,
338
- assets: [
339
- { input: 'src', glob: 'favicon.ico', output: '' },
340
- { input: 'src\\assets', glob: '**/*', output: 'assets' },
341
- ...opt.dev && opt.cordovaPlatforms ? opt.cordovaPlatforms.mapMany((platform) => [
342
- {
343
- input: `.cache\\cordova\\platforms\\${platform}\\platform_www\\plugins`,
344
- glob: '**/*',
345
- output: `cordova-${platform}/plugins`
346
- },
347
- {
348
- input: `.cache\\cordova\\platforms\\${platform}\\platform_www`,
349
- glob: 'cordova.js',
350
- output: `cordova-${platform}`
351
- },
352
- {
353
- input: `.cache\\cordova\\platforms\\${platform}\\platform_www`,
354
- glob: 'cordova_plugins.js',
355
- output: `cordova-${platform}`
356
- },
357
- {
358
- input: `.cache\\cordova\\platforms\\${platform}\\www`,
359
- glob: 'config.xml',
360
- output: `cordova-${platform}`
361
- },
362
- ]) : []
438
+ external: [],
439
+ conditions: ['style', 'sass'],
440
+ mainFields: ['style', 'sass'],
441
+ legalComments: !this._opt.dev ? "none" : "eof",
442
+ entryPoints: { styles: 'angular:styles/global;styles' },
443
+ plugins: [
444
+ createVirtualModulePlugin({
445
+ namespace: "angular:styles/global",
446
+ transformPath: (currPath) => currPath.split(';', 2)[1],
447
+ loadContent: () => ({
448
+ contents: `@import 'src/styles.scss';`,
449
+ loader: 'css',
450
+ resolveDir: this._opt.pkgPath
451
+ }),
452
+ }),
453
+ pluginFactory.create(SassStylesheetLanguage),
454
+ pluginFactory.create(CssStylesheetLanguage),
455
+ createCssResourcePlugin(this._sourceFileCache.loadResultCache),
363
456
  ],
364
- outputNames: { bundles: '[name]', media: 'media/[name]' },
365
- fileReplacements: undefined,
366
- globalStyles: [{ name: 'styles', files: ["src/styles.scss"], initial: true }],
367
- globalScripts: [],
368
- serviceWorker: FsUtil.exists(swFilePath) ? swFilePath : undefined,
369
- indexHtmlOptions: {
370
- input: indexHtmlFilePath,
371
- output: 'index.html',
372
- insertionOrder: [
373
- ['runtime', true],
374
- ['polyfills', true],
375
- ['styles', false],
376
- ['vendor', true],
377
- ['main', true],
378
- ...opt.builderType === "cordova" ? [
379
- ["cordova-entry", true]
380
- ] : []
381
- ]
382
- },
383
- tailwindConfiguration: undefined
384
- };
457
+ }, () => true);
385
458
  }
386
459
  }
387
460
  //# sourceMappingURL=SdNgBundler.js.map