@simplysm/sd-cli 11.0.8 → 11.0.11

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 (64) 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.d.ts +21 -0
  4. package/dist/build-tools/SdCliCordova.js +182 -0
  5. package/dist/build-tools/SdCliCordova.js.map +1 -0
  6. package/dist/build-tools/SdCliNgRoutesFileGenerator.d.ts +4 -0
  7. package/dist/build-tools/SdCliNgRoutesFileGenerator.js +64 -0
  8. package/dist/build-tools/SdCliNgRoutesFileGenerator.js.map +1 -0
  9. package/dist/build-tools/SdLinter.js +8 -1
  10. package/dist/build-tools/SdLinter.js.map +1 -1
  11. package/dist/build-tools/SdNgBundler.d.ts +16 -5
  12. package/dist/build-tools/SdNgBundler.js +280 -179
  13. package/dist/build-tools/SdNgBundler.js.map +1 -1
  14. package/dist/build-tools/SdTsBundler.d.ts +6 -5
  15. package/dist/build-tools/SdTsBundler.js +78 -80
  16. package/dist/build-tools/SdTsBundler.js.map +1 -1
  17. package/dist/build-tools/SdTsCompiler.d.ts +1 -0
  18. package/dist/build-tools/SdTsCompiler.js +5 -1
  19. package/dist/build-tools/SdTsCompiler.js.map +1 -1
  20. package/dist/builders/SdCliClientBuilder.d.ts +1 -0
  21. package/dist/builders/SdCliClientBuilder.js +62 -27
  22. package/dist/builders/SdCliClientBuilder.js.map +1 -1
  23. package/dist/builders/SdCliServerBuilder.d.ts +6 -2
  24. package/dist/builders/SdCliServerBuilder.js +107 -141
  25. package/dist/builders/SdCliServerBuilder.js.map +1 -1
  26. package/dist/builders/SdCliTsLibBuilder.d.ts +6 -3
  27. package/dist/builders/SdCliTsLibBuilder.js +42 -45
  28. package/dist/builders/SdCliTsLibBuilder.js.map +1 -1
  29. package/dist/commons.d.ts +22 -2
  30. package/dist/entry/SdCliElectron.js +3 -3
  31. package/dist/entry/SdCliElectron.js.map +1 -1
  32. package/dist/entry/SdCliProject.d.ts +0 -3
  33. package/dist/entry/SdCliProject.js +10 -33
  34. package/dist/entry/SdCliProject.js.map +1 -1
  35. package/dist/index.d.ts +4 -0
  36. package/dist/index.js +4 -0
  37. package/dist/index.js.map +1 -1
  38. package/dist/sd-cli.js +27 -21
  39. package/dist/sd-cli.js.map +1 -1
  40. package/dist/utils/SdMemoryLoadResultCache.d.ts +9 -0
  41. package/dist/utils/SdMemoryLoadResultCache.js +39 -0
  42. package/dist/utils/SdMemoryLoadResultCache.js.map +1 -0
  43. package/dist/utils/SdSourceFileCache.d.ts +5 -0
  44. package/dist/utils/SdSourceFileCache.js +9 -0
  45. package/dist/utils/SdSourceFileCache.js.map +1 -0
  46. package/lib/cordova-entry.js +22 -0
  47. package/package.json +19 -16
  48. package/src/build-cluster.ts +26 -36
  49. package/src/build-tools/SdCliCordova.ts +240 -0
  50. package/src/build-tools/SdCliNgRoutesFileGenerator.ts +80 -0
  51. package/src/build-tools/SdLinter.ts +12 -1
  52. package/src/build-tools/SdNgBundler.ts +428 -288
  53. package/src/build-tools/SdTsBundler.ts +86 -86
  54. package/src/build-tools/SdTsCompiler.ts +6 -1
  55. package/src/builders/SdCliClientBuilder.ts +76 -34
  56. package/src/builders/SdCliServerBuilder.ts +64 -63
  57. package/src/builders/SdCliTsLibBuilder.ts +58 -50
  58. package/src/commons.ts +24 -2
  59. package/src/entry/SdCliElectron.ts +3 -3
  60. package/src/entry/SdCliProject.ts +12 -41
  61. package/src/index.ts +4 -0
  62. package/src/sd-cli.ts +31 -21
  63. package/src/utils/SdMemoryLoadResultCache.ts +44 -0
  64. package/src/utils/SdSourceFileCache.ts +6 -0
@@ -1,27 +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
25
  constructor(_opt) {
20
26
  this._opt = _opt;
21
- this._logger = Logger.get(["simplysm", "sd-cli", "SdNgEsbuildBuilder"]);
22
- this._sourceFileCache = new SourceFileCache();
27
+ this._sourceFileCache = new SdSourceFileCache();
23
28
  this._outputCache = new Map();
24
- 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}/` : ``;
25
37
  }
26
38
  removeCache(filePaths) {
27
39
  this._sourceFileCache.invalidate(filePaths);
@@ -56,26 +68,26 @@ export class SdNgBundler {
56
68
  ];
57
69
  const watchFilePaths = [
58
70
  ...this._sourceFileCache.keys(),
59
- ...this._sourceFileCache.babelFileCache.keys()
60
- ].map((item) => path.resolve(item));
71
+ ...this._sourceFileCache.babelFileCache.keys(),
72
+ ...this._sourceFileCache.loadResultCache.fileDependencies.keys()
73
+ ].map((item) => path.resolve(item)).distinct();
61
74
  let affectedSourceFilePaths = watchFilePaths.filter((item) => PathUtil.isChildPath(item, this._opt.pkgPath));
62
75
  if (bundlingResult.errors) {
63
- return {
64
- filePaths: watchFilePaths,
65
- affectedFilePaths: affectedSourceFilePaths,
66
- results
67
- };
76
+ // TODO: 제대로 deps를 적용해야함.. 코드 분석 필요
77
+ this._depsMap = this._depsMap ?? new Map();
68
78
  }
69
- const depsMap = new Map();
70
- for (const entry of Object.entries(bundlingResult.metafile.inputs)) {
71
- for (const imp of entry[1].imports) {
72
- const deps = depsMap.getOrCreate(path.resolve(this._opt.pkgPath, imp.path), new Set());
73
- deps.add(path.resolve(this._opt.pkgPath, 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
+ }
74
86
  }
75
87
  }
76
88
  const searchAffectedFiles = (filePath, prev) => {
77
89
  const result = new Set(prev);
78
- const importerPaths = depsMap.get(filePath);
90
+ const importerPaths = this._depsMap.get(filePath);
79
91
  if (!importerPaths)
80
92
  return result;
81
93
  for (const importerPath of importerPaths) {
@@ -94,47 +106,83 @@ export class SdNgBundler {
94
106
  }
95
107
  affectedSourceFilePaths = Array.from(affectedFilePathSet.values()).filter((item) => PathUtil.isChildPath(item, this._opt.pkgPath));
96
108
  }
109
+ if (bundlingResult.errors) {
110
+ return {
111
+ filePaths: watchFilePaths,
112
+ affectedFilePaths: affectedSourceFilePaths,
113
+ results
114
+ };
115
+ }
97
116
  const executionResult = new ExecutionResult(this._contexts, this._sourceFileCache);
98
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
+ // }
99
133
  //-- index
100
- if (this._options.indexHtmlOptions) {
101
- const genIndexHtmlResult = await generateIndexHtml(bundlingResult.initialFiles, executionResult, this._options);
102
- if (genIndexHtmlResult.warnings.length > 0) {
103
- this._logger.warn(...genIndexHtmlResult.warnings);
104
- }
105
- if (genIndexHtmlResult.errors.length > 0) {
106
- this._logger.warn(...genIndexHtmlResult.errors);
107
- }
108
- 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
+ });
109
145
  }
110
- //-- copy assets
111
- if (this._options.assets) {
112
- 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
+ });
113
156
  }
157
+ executionResult.addOutputFile("index.html", genIndexHtmlResult.content);
158
+ //-- copy assets
159
+ executionResult.assetFiles.push(...(await this._copyAssetsAsync()));
114
160
  //-- extract 3rdpartylicenses
115
- if (this._options.extractLicenses) {
116
- 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));
117
163
  }
118
164
  //-- service worker
119
- if (this._options.serviceWorker !== undefined) {
165
+ if (FsUtil.exists(this._swConfFilePath)) {
120
166
  try {
121
- 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);
122
168
  executionResult.addOutputFile('ngsw.json', serviceWorkerResult.manifest);
123
169
  executionResult.assetFiles.push(...serviceWorkerResult.assetFiles);
124
170
  }
125
- catch (error) {
126
- this._logger.error(error instanceof Error ? error.message : `${error}`);
127
- return {
128
- filePaths: watchFilePaths,
129
- affectedFilePaths: affectedSourceFilePaths,
130
- results
131
- };
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
+ });
132
181
  }
133
182
  }
134
183
  //-- write
135
- const distPath = path.resolve(this._options.outputPath, "dist", ...(this._opt.builderType === "web" ? [] : [this._opt.builderType]));
136
184
  for (const outputFile of executionResult.outputFiles) {
137
- const distFilePath = path.resolve(distPath, outputFile.path);
185
+ const distFilePath = path.resolve(this._opt.outputPath, outputFile.path);
138
186
  const prev = this._outputCache.get(distFilePath);
139
187
  if (prev !== Buffer.from(outputFile.contents).toString("base64")) {
140
188
  await FsUtil.writeFileAsync(distFilePath, outputFile.contents);
@@ -145,7 +193,7 @@ export class SdNgBundler {
145
193
  const prev = this._outputCache.get(assetFile.source);
146
194
  const curr = FsUtil.lstat(assetFile.source).mtime.getTime();
147
195
  if (prev !== curr) {
148
- await FsUtil.copyAsync(assetFile.source, path.resolve(distPath, assetFile.destination));
196
+ await FsUtil.copyAsync(assetFile.source, path.resolve(this._opt.outputPath, assetFile.destination));
149
197
  this._outputCache.set(assetFile.source, curr);
150
198
  }
151
199
  }
@@ -155,43 +203,114 @@ export class SdNgBundler {
155
203
  results
156
204
  };
157
205
  }
158
- async _getAppContextAsync() {
159
- const esbuildOption = await this._getEsBuildOptionsAsync();
160
- 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
+ }
161
278
  }
162
- _getStyleContext() {
163
- const esbuildOptions = createGlobalStylesBundleOptions(this._options, [
164
- 'chrome117.0', 'chrome116.0',
165
- 'edge117.0', 'edge116.0',
166
- 'firefox118.0', 'firefox115.0',
167
- 'ios17.0', 'ios16.6',
168
- 'ios16.5', 'ios16.4',
169
- 'ios16.3', 'ios16.2',
170
- 'ios16.1', 'ios16.0',
171
- 'safari17.0', 'safari16.6',
172
- 'safari16.5', 'safari16.4',
173
- 'safari16.3', 'safari16.2',
174
- 'safari16.1', 'safari16.0'
175
- ], true, this._sourceFileCache.loadResultCache);
176
- 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);
177
307
  }
178
- async _getEsBuildOptionsAsync() {
179
- const pkgNpmConf = FsUtil.readJson(path.resolve(this._options.workspaceRoot, "package.json"));
180
- const { pluginOptions, styleOptions } = createCompilerPluginOptions(this._options, [
181
- 'chrome117.0', 'chrome116.0',
182
- 'edge117.0', 'edge116.0',
183
- 'firefox118.0', 'firefox115.0',
184
- 'ios17.0', 'ios16.6',
185
- 'ios16.5', 'ios16.4',
186
- 'ios16.3', 'ios16.2',
187
- 'ios16.1', 'ios16.0',
188
- 'safari17.0', 'safari16.6',
189
- 'safari16.5', 'safari16.4',
190
- 'safari16.3', 'safari16.2',
191
- 'safari16.1', 'safari16.0'
192
- ], this._sourceFileCache);
193
- return {
194
- 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,
195
314
  bundle: true,
196
315
  keepNames: true,
197
316
  format: 'esm',
@@ -199,50 +318,42 @@ export class SdNgBundler {
199
318
  conditions: ['es2020', 'es2015', 'module'],
200
319
  resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
201
320
  metafile: true,
202
- legalComments: this._options.watch ? 'eof' : 'none',
321
+ legalComments: this._opt.dev ? 'eof' : 'none',
203
322
  logLevel: 'silent',
204
- minifyIdentifiers: !this._options.watch,
205
- minifySyntax: !this._options.watch,
206
- minifyWhitespace: !this._options.watch,
323
+ minifyIdentifiers: !this._opt.dev,
324
+ minifySyntax: !this._opt.dev,
325
+ minifyWhitespace: !this._opt.dev,
207
326
  pure: ['forwardRef'],
208
- outdir: this._options.outputPath,
327
+ outdir: this._opt.pkgPath,
209
328
  outExtension: undefined,
210
- sourcemap: this._options.watch,
329
+ sourcemap: this._opt.dev,
211
330
  splitting: true,
212
331
  chunkNames: 'chunk-[hash]',
213
- tsconfig: this._options.tsconfig,
332
+ tsconfig: this._tsConfigFilePath,
214
333
  external: [],
215
334
  write: false,
216
335
  preserveSymlinks: false,
217
336
  define: {
218
- ...!this._options.watch ? { ngDevMode: 'false' } : {},
337
+ ...!this._opt.dev ? { ngDevMode: 'false' } : {},
219
338
  ngJitMode: 'false',
220
339
  global: 'global',
221
340
  process: 'process',
222
341
  Buffer: 'Buffer',
223
- 'process.env.SD_VERSION': JSON.stringify(pkgNpmConf.version),
224
- "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])) : {}
225
345
  },
226
346
  platform: 'browser',
227
347
  mainFields: ['es2020', 'es2015', 'browser', 'module', 'main'],
228
348
  entryNames: '[name]',
229
349
  entryPoints: {
230
- ...this._options.entryPoints,
231
- 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
+ } : {}
232
355
  },
233
- target: [
234
- 'chrome117.0', 'chrome116.0',
235
- 'edge117.0', 'edge116.0',
236
- 'firefox118.0', 'firefox115.0',
237
- 'ios17.0', 'ios16.6',
238
- 'ios16.5', 'ios16.4',
239
- 'ios16.3', 'ios16.2',
240
- 'ios16.1', 'ios16.0',
241
- 'safari17.0', 'safari16.6',
242
- 'safari16.5', 'safari16.4',
243
- 'safari16.3', 'safari16.2',
244
- 'safari16.1', 'safari16.0'
245
- ],
356
+ target: this._browserTarget,
246
357
  supported: { 'async-await': false, 'object-rest-spread': false },
247
358
  loader: {
248
359
  ".png": "file",
@@ -275,85 +386,75 @@ export class SdNgBundler {
275
386
  loadContent: () => ({
276
387
  contents: `import "./src/polyfills.ts";`,
277
388
  loader: 'js',
278
- resolveDir: this._options.workspaceRoot
389
+ resolveDir: this._opt.pkgPath
279
390
  })
280
391
  }),
281
392
  createSourcemapIgnorelistPlugin(),
282
- 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
+ }),
283
414
  nodeStdLibBrowserPlugin(nodeStdLibBrowser)
284
415
  ]
285
- };
416
+ });
286
417
  }
287
- _getOptions(opt) {
288
- const mainFilePath = path.resolve(opt.pkgPath, "src/main.ts");
289
- const tsconfigFilePath = path.resolve(opt.pkgPath, "tsconfig.json");
290
- const indexHtmlFilePath = path.resolve(opt.pkgPath, "src/index.html");
291
- const swFilePath = path.resolve(opt.pkgPath, "ngsw-config.json");
292
- const cacheBasePath = path.resolve(opt.pkgPath, ".cache");
293
- const pkgName = path.basename(opt.pkgPath);
294
- return {
295
- advancedOptimizations: true,
296
- allowedCommonJsDependencies: [],
297
- baseHref: `/${pkgName}/`,
298
- cacheOptions: {
299
- enabled: true,
300
- basePath: cacheBasePath,
301
- path: path.resolve(cacheBasePath, opt.builderType)
302
- },
303
- crossOrigin: CrossOrigin.None,
304
- deleteOutputPath: true,
305
- externalDependencies: [],
306
- extractLicenses: !opt.dev,
307
- inlineStyleLanguage: 'scss',
308
- jit: false,
309
- stats: false,
310
- polyfills: ["./src/polyfills.ts"],
311
- poll: undefined,
312
- progress: true,
313
- 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,
314
437
  preserveSymlinks: false,
315
- stylePreprocessorOptions: { includePaths: [] },
316
- subresourceIntegrity: false,
317
- serverEntryPoint: undefined,
318
- prerenderOptions: undefined,
319
- appShellOptions: undefined,
320
- ssrOptions: undefined,
321
- verbose: false,
322
- watch: opt.dev,
323
- workspaceRoot: opt.pkgPath,
324
- entryPoints: { main: mainFilePath },
325
- optimizationOptions: {
326
- scripts: !opt.dev,
327
- styles: { minify: !opt.dev, inlineCritical: !opt.dev },
328
- fonts: { inline: !opt.dev }
329
- },
330
- outputPath: opt.pkgPath,
331
- outExtension: undefined,
332
- sourcemapOptions: { vendor: false, hidden: false, scripts: opt.dev, styles: opt.dev },
333
- tsconfig: tsconfigFilePath,
334
- projectRoot: opt.pkgPath,
335
- assets: [
336
- { glob: 'favicon.ico', input: 'src', output: '' },
337
- { glob: '**/*', input: 'src\\assets', output: 'assets' }
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),
338
456
  ],
339
- outputNames: { bundles: '[name]', media: 'media/[name]' },
340
- fileReplacements: undefined,
341
- globalStyles: [{ name: 'styles', files: ["src/styles.scss"], initial: true }],
342
- globalScripts: [],
343
- serviceWorker: FsUtil.exists(swFilePath) ? swFilePath : undefined,
344
- indexHtmlOptions: {
345
- input: indexHtmlFilePath,
346
- output: 'index.html',
347
- insertionOrder: [
348
- ['runtime', true],
349
- ['polyfills', true],
350
- ['styles', false],
351
- ['vendor', true],
352
- ['main', true]
353
- ]
354
- },
355
- tailwindConfiguration: undefined
356
- };
457
+ }, () => true);
357
458
  }
358
459
  }
359
460
  //# sourceMappingURL=SdNgBundler.js.map