ng-packagr 15.0.2 → 15.1.0-next.0

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.
@@ -8,7 +8,8 @@ import { OutputFileCache } from '../ng-package/nodes';
8
8
  export interface RollupOptions {
9
9
  moduleName: string;
10
10
  entry: string;
11
- dest: string;
11
+ entryName: string;
12
+ dir: string;
12
13
  sourceRoot: string;
13
14
  downlevel?: boolean;
14
15
  cache?: rollup.RollupCache;
@@ -19,6 +20,5 @@ export interface RollupOptions {
19
20
  /** Runs rollup over the given entry file, writes a bundle file. */
20
21
  export declare function rollupBundleFile(opts: RollupOptions): Promise<{
21
22
  cache: rollup.RollupCache;
22
- code: string;
23
- map: rollup.SourceMap;
23
+ files: (rollup.OutputChunk | rollup.OutputAsset)[];
24
24
  }>;
@@ -38,13 +38,12 @@ const file_loader_plugin_1 = require("./file-loader-plugin");
38
38
  /** Runs rollup over the given entry file, writes a bundle file. */
39
39
  async function rollupBundleFile(opts) {
40
40
  var _a;
41
- log.debug(`rollup (v${rollup.VERSION}) ${opts.entry} to ${opts.dest}`);
41
+ log.debug(`rollup (v${rollup.VERSION}) ${opts.entry} to ${opts.dir}`);
42
42
  const cacheDirectory = opts.cacheDirectory;
43
43
  // Create the bundle
44
44
  const bundle = await rollup.rollup({
45
45
  context: 'this',
46
46
  external: moduleId => isExternalDependency(moduleId),
47
- inlineDynamicImports: false,
48
47
  cache: (_a = opts.cache) !== null && _a !== void 0 ? _a : (cacheDirectory ? await (0, cache_1.readCacheEntry)(cacheDirectory, opts.cacheKey) : undefined),
49
48
  input: opts.entry,
50
49
  plugins: [
@@ -73,19 +72,20 @@ async function rollupBundleFile(opts) {
73
72
  const output = await bundle.write({
74
73
  name: opts.moduleName,
75
74
  format: 'es',
76
- file: opts.dest,
75
+ dir: opts.dir,
76
+ inlineDynamicImports: false,
77
+ chunkFileNames: opts.entryName + '-[name]-[hash].mjs',
78
+ entryFileNames: opts.entryName + '.mjs',
77
79
  banner: '',
78
80
  sourcemap: true,
79
81
  });
80
82
  if (cacheDirectory) {
81
83
  await (0, cache_1.saveCacheEntry)(cacheDirectory, opts.cacheKey, JSON.stringify(bundle.cache));
82
84
  }
83
- const { code, map } = output.output[0];
84
85
  // Close the bundle to let plugins clean up their external processes or services
85
86
  await bundle.close();
86
87
  return {
87
- code: code + '//# sourceMapping' + `URL=${path.basename(opts.dest)}.map\n`,
88
- map,
88
+ files: output.output,
89
89
  cache: bundle.cache,
90
90
  };
91
91
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rollup.js","sourceRoot":"","sources":["../../../src/lib/flatten/rollup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sEAA6C;AAC7C,sFAAsD;AACtD,2CAA6B;AAC7B,+CAAiC;AAEjC,0CAAgE;AAChE,kDAAoC;AACpC,yDAAgE;AAChE,6DAAwD;AAmBxD,mEAAmE;AAC5D,KAAK,UAAU,gBAAgB,CACpC,IAAmB;;IAEnB,GAAG,CAAC,KAAK,CAAC,YAAY,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAEvE,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;IAE3C,oBAAoB;IACpB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC;QACjC,OAAO,EAAE,MAAM;QACf,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC,oBAAoB,CAAC,QAAQ,CAAC;QACpD,oBAAoB,EAAE,KAAK;QAC3B,KAAK,EAAE,MAAA,IAAI,CAAC,KAAK,mCAAI,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,IAAA,sBAAc,EAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACvG,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,OAAO,EAAE;YACP,IAAA,6BAAW,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K;KACpB,CAAC;AACJ,CAAC;AA7DD,4CA6DC;AAED,SAAS,oBAAoB,CAAC,QAAgB;IAC5C,oEAAoE;IACpE,yFAAyF;IACzF,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QACrF,yGAAyG;QACzG,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import rollupJson from '@rollup/plugin-json';\nimport nodeResolve from '@rollup/plugin-node-resolve';\nimport * as path from 'path';\nimport * as rollup from 'rollup';\nimport { OutputFileCache } from '../ng-package/nodes';\nimport { readCacheEntry, saveCacheEntry } from '../utils/cache';\nimport * as log from '../utils/log';\nimport { downlevelCodeWithTscPlugin } from './downlevel-plugin';\nimport { fileLoaderPlugin } from './file-loader-plugin';\n\n/**\n * Options used in `ng-packagr` for writing flat bundle files.\n *\n * These options are passed through to rollup.\n */\nexport interface RollupOptions {\n moduleName: string;\n entry: string;\n dest: string;\n sourceRoot: string;\n downlevel?: boolean;\n cache?: rollup.RollupCache;\n cacheDirectory?: string | false;\n fileCache: OutputFileCache;\n cacheKey: string;\n}\n\n/** Runs rollup over the given entry file, writes a bundle file. */\nexport async function rollupBundleFile(\n opts: RollupOptions,\n): Promise<{ cache: rollup.RollupCache; code: string; map: rollup.SourceMap }> {\n log.debug(`rollup (v${rollup.VERSION}) ${opts.entry} to ${opts.dest}`);\n\n const cacheDirectory = opts.cacheDirectory;\n\n // Create the bundle\n const bundle = await rollup.rollup({\n context: 'this',\n external: moduleId => isExternalDependency(moduleId),\n inlineDynamicImports: false,\n cache: opts.cache ?? (cacheDirectory ? await readCacheEntry(cacheDirectory, opts.cacheKey) : undefined),\n input: opts.entry,\n plugins: [\n nodeResolve(),\n rollupJson(),\n fileLoaderPlugin(opts.fileCache),\n opts.downlevel ? downlevelCodeWithTscPlugin() : undefined,\n ],\n onwarn: warning => {\n switch (warning.code) {\n case 'CIRCULAR_DEPENDENCY':\n case 'UNUSED_EXTERNAL_IMPORT':\n case 'THIS_IS_UNDEFINED':\n break;\n\n default:\n log.warn(warning.message);\n break;\n }\n },\n preserveSymlinks: true,\n // Disable treeshaking when generating bundles\n // see: https://github.com/angular/angular/pull/32069\n treeshake: false,\n });\n\n // Output the bundle to disk\n const output = await bundle.write({\n name: opts.moduleName,\n format: 'es',\n file: opts.dest,\n banner: '',\n sourcemap: true,\n });\n\n if (cacheDirectory) {\n await saveCacheEntry(cacheDirectory, opts.cacheKey, JSON.stringify(bundle.cache));\n }\n\n const { code, map } = output.output[0];\n\n // Close the bundle to let plugins clean up their external processes or services\n await bundle.close();\n\n return {\n code: code + '//# sourceMapping' + `URL=${path.basename(opts.dest)}.map\\n`,\n map,\n cache: bundle.cache,\n };\n}\n\nfunction isExternalDependency(moduleId: string): boolean {\n // more information about why we don't check for 'node_modules' path\n // https://github.com/rollup/rollup-plugin-node-resolve/issues/110#issuecomment-350353632\n if (moduleId.startsWith('.') || moduleId.startsWith('/') || path.isAbsolute(moduleId)) {\n // if it's either 'absolute', marked to embed, starts with a '.' or '/' or is the umd bundle and is tslib\n return false;\n }\n\n return true;\n}\n"]}
1
+ {"version":3,"file":"rollup.js","sourceRoot":"","sources":["../../../src/lib/flatten/rollup.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sEAA6C;AAC7C,sFAAsD;AACtD,2CAA6B;AAC7B,+CAAiC;AAEjC,0CAAgE;AAChE,kDAAoC;AACpC,yDAAgE;AAChE,6DAAwD;AAoBxD,mEAAmE;AAC5D,KAAK,UAAU,gBAAgB,CACpC,IAAmB;;IAEnB,GAAG,CAAC,KAAK,CAAC,YAAY,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAEtE,MAAM,cAAc,GAAG,IAAI,CAAC,cAA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AG,MAAM;QACvC,MAAM,EAAE,EAAE;QACV,SAAS,EAAE,IAAI;KAChB,CAAC,CAAC;IAEH,IAAI,cAAc,EAAE;QAClB,MAAM,IAAA,sBAAc,EAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;KACnF;IAED,gFAAgF;IAChF,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IAErB,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM;QACpB,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAC;AACJ,CAAC;AA5DD,4CA4DC;AAED,SAAS,oBAAoB,CAAC,QAAgB;IAC5C,oEAAoE;IACpE,yFAAyF;IACzF,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QACrF,yGAAyG;QACzG,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import rollupJson from '@rollup/plugin-json';\nimport nodeResolve from '@rollup/plugin-node-resolve';\nimport * as path from 'path';\nimport * as rollup from 'rollup';\nimport { OutputFileCache } from '../ng-package/nodes';\nimport { readCacheEntry, saveCacheEntry } from '../utils/cache';\nimport * as log from '../utils/log';\nimport { downlevelCodeWithTscPlugin } from './downlevel-plugin';\nimport { fileLoaderPlugin } from './file-loader-plugin';\n\n/**\n * Options used in `ng-packagr` for writing flat bundle files.\n *\n * These options are passed through to rollup.\n */\nexport interface RollupOptions {\n moduleName: string;\n entry: string;\n entryName: string;\n dir: string;\n sourceRoot: string;\n downlevel?: boolean;\n cache?: rollup.RollupCache;\n cacheDirectory?: string | false;\n fileCache: OutputFileCache;\n cacheKey: string;\n}\n\n/** Runs rollup over the given entry file, writes a bundle file. */\nexport async function rollupBundleFile(\n opts: RollupOptions,\n): Promise<{ cache: rollup.RollupCache; files: (rollup.OutputChunk | rollup.OutputAsset)[] }> {\n log.debug(`rollup (v${rollup.VERSION}) ${opts.entry} to ${opts.dir}`);\n\n const cacheDirectory = opts.cacheDirectory;\n\n // Create the bundle\n const bundle = await rollup.rollup({\n context: 'this',\n external: moduleId => isExternalDependency(moduleId),\n cache: opts.cache ?? (cacheDirectory ? await readCacheEntry(cacheDirectory, opts.cacheKey) : undefined),\n input: opts.entry,\n plugins: [\n nodeResolve(),\n rollupJson(),\n fileLoaderPlugin(opts.fileCache),\n opts.downlevel ? downlevelCodeWithTscPlugin() : undefined,\n ],\n onwarn: warning => {\n switch (warning.code) {\n case 'CIRCULAR_DEPENDENCY':\n case 'UNUSED_EXTERNAL_IMPORT':\n case 'THIS_IS_UNDEFINED':\n break;\n\n default:\n log.warn(warning.message);\n break;\n }\n },\n preserveSymlinks: true,\n // Disable treeshaking when generating bundles\n // see: https://github.com/angular/angular/pull/32069\n treeshake: false,\n });\n\n // Output the bundle to disk\n const output = await bundle.write({\n name: opts.moduleName,\n format: 'es',\n dir: opts.dir,\n inlineDynamicImports: false,\n chunkFileNames: opts.entryName + '-[name]-[hash].mjs',\n entryFileNames: opts.entryName + '.mjs',\n banner: '',\n sourcemap: true,\n });\n\n if (cacheDirectory) {\n await saveCacheEntry(cacheDirectory, opts.cacheKey, JSON.stringify(bundle.cache));\n }\n\n // Close the bundle to let plugins clean up their external processes or services\n await bundle.close();\n\n return {\n files: output.output,\n cache: bundle.cache,\n };\n}\n\nfunction isExternalDependency(moduleId: string): boolean {\n // more information about why we don't check for 'node_modules' path\n // https://github.com/rollup/rollup-plugin-node-resolve/issues/110#issuecomment-350353632\n if (moduleId.startsWith('.') || moduleId.startsWith('/') || path.isAbsolute(moduleId)) {\n // if it's either 'absolute', marked to embed, starts with a '.' or '/' or is the umd bundle and is tslib\n return false;\n }\n\n return true;\n}\n"]}
@@ -38,17 +38,17 @@ const ng_compiler_cli_1 = require("../../utils/ng-compiler-cli");
38
38
  const nodes_1 = require("../nodes");
39
39
  const compileNgcTransformFactory = (StylesheetProcessor, options) => {
40
40
  return (0, transform_1.transformFromPromise)(async (graph) => {
41
- var _a;
42
- var _b;
41
+ var _a, _b;
42
+ var _c;
43
43
  const spinner = (0, ora_1.default)({
44
44
  hideCursor: false,
45
45
  discardStdin: false,
46
46
  });
47
+ const entryPoints = graph.filter(nodes_1.isEntryPoint);
48
+ const entryPoint = entryPoints.find((0, nodes_1.isEntryPointInProgress)());
49
+ const ngPackageNode = graph.find(nodes_1.isPackage);
50
+ const projectBasePath = ngPackageNode.data.primary.basePath;
47
51
  try {
48
- const entryPoints = graph.filter(nodes_1.isEntryPoint);
49
- const entryPoint = entryPoints.find((0, nodes_1.isEntryPointInProgress)());
50
- const ngPackageNode = graph.find(nodes_1.isPackage);
51
- const projectBasePath = ngPackageNode.data.primary.basePath;
52
52
  // Add paths mappings for dependencies
53
53
  const tsConfig = (0, tsconfig_1.setDependenciesTsConfigPaths)(entryPoint.data.tsConfig, entryPoints);
54
54
  // Compile TypeScript sources
@@ -61,7 +61,7 @@ const compileNgcTransformFactory = (StylesheetProcessor, options) => {
61
61
  // Only run the async version of NGCC during the primary entrypoint processing.
62
62
  await ngccProcessor.process();
63
63
  }
64
- (_a = (_b = entryPoint.cache).stylesheetProcessor) !== null && _a !== void 0 ? _a : (_b.stylesheetProcessor = new StylesheetProcessor(projectBasePath, basePath, cssUrl, styleIncludePaths, options.cacheEnabled && options.cacheDirectory));
64
+ (_a = (_c = entryPoint.cache).stylesheetProcessor) !== null && _a !== void 0 ? _a : (_c.stylesheetProcessor = new StylesheetProcessor(projectBasePath, basePath, cssUrl, styleIncludePaths, options.cacheEnabled && options.cacheDirectory));
65
65
  await (0, compile_source_files_1.compileSourceFiles)(graph, tsConfig, moduleResolutionCache, {
66
66
  outDir: path.dirname(esm2020),
67
67
  declarationDir: path.dirname(declarations),
@@ -73,6 +73,11 @@ const compileNgcTransformFactory = (StylesheetProcessor, options) => {
73
73
  spinner.fail();
74
74
  throw error;
75
75
  }
76
+ finally {
77
+ if (!options.watch) {
78
+ (_b = entryPoint.cache.stylesheetProcessor) === null || _b === void 0 ? void 0 : _b.destroy();
79
+ }
80
+ }
76
81
  spinner.succeed();
77
82
  return graph;
78
83
  });
@@ -1 +1 @@
1
- {"version":3,"file":"compile-ngc.transform.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/compile-ngc.transform.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAsB;AACtB,2CAA6B;AAC7B,4DAA4B;AAC5B,qDAAwE;AACxE,yEAAoE;AACpE,6DAAyD;AAEzD,gDAAiE;AACjE,iEAA8D;AAC9D,oCAAwG;AAGjG,MAAM,0BAA0B,GAAG,CACxC,mBAAoD,EACpD,OAAyB,EACd,EAAE;IACb,OAAO,IAAA,gCAAoB,EAAC,KAAK,EAAC,KAAK,EAAC,EAAE;;;QACxC,MAAM,OAAO,GAAG,IAAA,aAAG,EAAC;YAClB,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;QAEH,IAAI;YACF,MAAM,WAAW,GAAqB,KAAK,CAAC,MAAM,CAAC,oBAAY,CAAC,CAAC;YACjE,MAAM,UAAU,GAAmB,WAAW,CAAC,IAAI,CAAC,IAAA,8BAAsB,GAAE,CAAC,CAAC;YAC9E,MAAM,aAAa,GAAgB,KAAK,CAAC,IAAI,CAAC,iBAAS,CAAC,CAAC;YACzD,MAAM,eAAe,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;YAE5D,sCAAsC;YACtC,MAAM,QAAQ,GAAG,IAAA,uCAA4B,EAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YAErF,6BAA6B;YAC7B,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC;YACnE,MAAM,EAAE,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AK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAtEW,QAAA,0BAA0B,8BAsErC","sourcesContent":["import ora from 'ora';\nimport * as path from 'path';\nimport ts from 'typescript';\nimport { Transform, transformFromPromise } from '../../graph/transform';\nimport { compileSourceFiles } from '../../ngc/compile-source-files';\nimport { NgccProcessor } from '../../ngc/ngcc-processor';\nimport { StylesheetProcessor as StylesheetProcessorClass } from '../../styles/stylesheet-processor';\nimport { setDependenciesTsConfigPaths } from '../../ts/tsconfig';\nimport { ngccCompilerCli } from '../../utils/ng-compiler-cli';\nimport { EntryPointNode, PackageNode, isEntryPoint, isEntryPointInProgress, isPackage } from '../nodes';\nimport { NgPackagrOptions } from '../options.di';\n\nexport const compileNgcTransformFactory = (\n StylesheetProcessor: typeof StylesheetProcessorClass,\n options: NgPackagrOptions,\n): Transform => {\n return transformFromPromise(async graph => {\n const spinner = ora({\n hideCursor: false,\n discardStdin: false,\n });\n\n try {\n const entryPoints: EntryPointNode[] = graph.filter(isEntryPoint);\n const entryPoint: EntryPointNode = entryPoints.find(isEntryPointInProgress());\n const ngPackageNode: PackageNode = graph.find(isPackage);\n const projectBasePath = ngPackageNode.data.primary.basePath;\n\n // Add paths mappings for dependencies\n const tsConfig = setDependenciesTsConfigPaths(entryPoint.data.tsConfig, entryPoints);\n\n // Compile TypeScript sources\n const { esm2020, declarations } = entryPoint.data.destinationFiles;\n const { basePath, cssUrl, styleIncludePaths } = entryPoint.data.entryPoint;\n const { moduleResolutionCache, ngccProcessingCache } = entryPoint.cache;\n\n spinner.start(\n `Compiling with Angular sources in Ivy ${tsConfig.options.compilationMode || 'full'} compilation mode.`,\n );\n const ngccProcessor = new NgccProcessor(\n await ngccCompilerCli(),\n ngccProcessingCache,\n tsConfig.project,\n tsConfig.options,\n entryPoints,\n );\n if (!entryPoint.data.entryPoint.isSecondaryEntryPoint) {\n // Only run the async version of NGCC during the primary entrypoint processing.\n await ngccProcessor.process();\n }\n\n entryPoint.cache.stylesheetProcessor ??= new StylesheetProcessor(\n projectBasePath,\n basePath,\n cssUrl,\n styleIncludePaths,\n options.cacheEnabled && options.cacheDirectory,\n );\n\n await compileSourceFiles(\n graph,\n tsConfig,\n moduleResolutionCache,\n {\n outDir: path.dirname(esm2020),\n declarationDir: path.dirname(declarations),\n declaration: true,\n target: ts.ScriptTarget.ES2020,\n },\n entryPoint.cache.stylesheetProcessor,\n ngccProcessor,\n options.watch,\n );\n } catch (error) {\n spinner.fail();\n throw error;\n }\n\n spinner.succeed();\n\n return graph;\n });\n};\n"]}
1
+ {"version":3,"file":"compile-ngc.transform.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/compile-ngc.transform.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAsB;AACtB,2CAA6B;AAC7B,4DAA4B;AAC5B,qDAAwE;AACxE,yEAAoE;AACpE,6DAAyD;AAEzD,gDAAiE;AACjE,iEAA8D;AAC9D,oCAAwG;AAGjG,MAAM,0BAA0B,GAAG,CACxC,mBAAoD,EACpD,OAAyB,EACd,EAAE;IACb,OAAO,IAAA,gCAAoB,EAAC,KAAK,EAAC,KAAK,EAAC,EAAE;;;QACxC,MAAM,OAAO,GAAG,IAAA,aAAG,EAAC;YAClB,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;QAEH,MAAM,WAAW,GAAqB,KAAK,CAAC,MAAM,CAAC,oBAAY,CAAC,CAAC;QACjE,MAAM,UAAU,GAAmB,WAAW,CAAC,IAAI,CAAC,IAAA,8BAAsB,GAAE,CAAC,CAAC;QAC9E,MAAM,aAAa,GAAgB,KAAK,CAAC,IAAI,CAAC,iBAAS,CAAC,CAAC;QACzD,MAAM,eAAe,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;QAE5D,IAAI;YACF,sCAAsC;YACtC,MAAM,QAAQ,GAAG,IAAA,uCAA4B,EAAC,UAAU,CAAC,I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AAC,KAAK,CACd,CAAC;SACH;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,IAAI,EAAE,CAAC;YACf,MAAM,KAAK,CAAC;SACb;gBAAS;YACR,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;gBAClB,MAAA,UAAU,CAAC,KAAK,CAAC,mBAAmB,0CAAE,OAAO,EAAE,CAAC;aACjD;SACF;QAED,OAAO,CAAC,OAAO,EAAE,CAAC;QAElB,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA1EW,QAAA,0BAA0B,8BA0ErC","sourcesContent":["import ora from 'ora';\nimport * as path from 'path';\nimport ts from 'typescript';\nimport { Transform, transformFromPromise } from '../../graph/transform';\nimport { compileSourceFiles } from '../../ngc/compile-source-files';\nimport { NgccProcessor } from '../../ngc/ngcc-processor';\nimport { StylesheetProcessor as StylesheetProcessorClass } from '../../styles/stylesheet-processor';\nimport { setDependenciesTsConfigPaths } from '../../ts/tsconfig';\nimport { ngccCompilerCli } from '../../utils/ng-compiler-cli';\nimport { EntryPointNode, PackageNode, isEntryPoint, isEntryPointInProgress, isPackage } from '../nodes';\nimport { NgPackagrOptions } from '../options.di';\n\nexport const compileNgcTransformFactory = (\n StylesheetProcessor: typeof StylesheetProcessorClass,\n options: NgPackagrOptions,\n): Transform => {\n return transformFromPromise(async graph => {\n const spinner = ora({\n hideCursor: false,\n discardStdin: false,\n });\n\n const entryPoints: EntryPointNode[] = graph.filter(isEntryPoint);\n const entryPoint: EntryPointNode = entryPoints.find(isEntryPointInProgress());\n const ngPackageNode: PackageNode = graph.find(isPackage);\n const projectBasePath = ngPackageNode.data.primary.basePath;\n\n try {\n // Add paths mappings for dependencies\n const tsConfig = setDependenciesTsConfigPaths(entryPoint.data.tsConfig, entryPoints);\n\n // Compile TypeScript sources\n const { esm2020, declarations } = entryPoint.data.destinationFiles;\n const { basePath, cssUrl, styleIncludePaths } = entryPoint.data.entryPoint;\n const { moduleResolutionCache, ngccProcessingCache } = entryPoint.cache;\n\n spinner.start(\n `Compiling with Angular sources in Ivy ${tsConfig.options.compilationMode || 'full'} compilation mode.`,\n );\n const ngccProcessor = new NgccProcessor(\n await ngccCompilerCli(),\n ngccProcessingCache,\n tsConfig.project,\n tsConfig.options,\n entryPoints,\n );\n if (!entryPoint.data.entryPoint.isSecondaryEntryPoint) {\n // Only run the async version of NGCC during the primary entrypoint processing.\n await ngccProcessor.process();\n }\n\n entryPoint.cache.stylesheetProcessor ??= new StylesheetProcessor(\n projectBasePath,\n basePath,\n cssUrl,\n styleIncludePaths,\n options.cacheEnabled && options.cacheDirectory,\n );\n\n await compileSourceFiles(\n graph,\n tsConfig,\n moduleResolutionCache,\n {\n outDir: path.dirname(esm2020),\n declarationDir: path.dirname(declarations),\n declaration: true,\n target: ts.ScriptTarget.ES2020,\n },\n entryPoint.cache.stylesheetProcessor,\n ngccProcessor,\n options.watch,\n );\n } catch (error) {\n spinner.fail();\n throw error;\n } finally {\n if (!options.watch) {\n entryPoint.cache.stylesheetProcessor?.destroy();\n }\n }\n\n spinner.succeed();\n\n return graph;\n });\n};\n"]}
@@ -12,6 +12,10 @@ export interface DestinationFiles {
12
12
  esm2020: string;
13
13
  /** Sub path of entrypoint distributable. */
14
14
  directory: string;
15
+ /** Absolute path of this entry point `FESM2020` directory */
16
+ fesm2020Dir: string;
17
+ /** Absolute path of this entry point `FESM2015` directory */
18
+ fesm2015Dir: string;
15
19
  }
16
20
  /**
17
21
  * An entry point - quoting Angular Package Format - is:
@@ -102,6 +102,8 @@ class NgEntryPoint {
102
102
  esm2020: pathJoinWithDest('esm2020', secondaryDir, `${flatModuleFile}.mjs`),
103
103
  fesm2020: pathJoinWithDest('fesm2020', `${flatModuleFile}.mjs`),
104
104
  fesm2015: pathJoinWithDest('fesm2015', `${flatModuleFile}.mjs`),
105
+ fesm2020Dir: pathJoinWithDest('fesm2020'),
106
+ fesm2015Dir: pathJoinWithDest('fesm2015'),
105
107
  };
106
108
  }
107
109
  $get(key) {
@@ -1 +1 @@
1
- {"version":3,"file":"entry-point.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/entry-point.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAG7B,2CAAkD;AAgBlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,YAAY;IACvB;IACE,+DAA+D;IAC/C,WAAgC;IAChD,wGAAwG;IACxF,aAA8B;IAC9C,6EAA6E;IAC7D,QAAgB;IAChC,iGAAiG;IAChF,aAAsC;QANvC,gBAAW,GAAX,WAAW,CAAqB;QAEhC,kBAAa,GAAb,aAAa,CAAiB;QAE9B,aAAQ,GAAR,QAAQ,CAAQ;QAEf,kBAAa,GAAb,aAAa,CAAyB;IACtD,CAAC;IAEJ,sEAAsE;IACtE,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IAED,iDAAiD;IACjD,IAAW,qBAAqB;QAC9B,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED,oEAAoE;IACpE,IAAW,eAAe;QACxB,IAAI,IAAI,CAAC,aAAa,EAAE;YACtB,OAAO,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC;SAC3C;aAAM;YACL,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;SACvD;IACH,CAAC;IAED,IAAW,gBAAgB;QACzB,IAAI,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC3C,IAAI,YAAY,GAAG,EAAE,CAAC;QAEtB,IAAI,IAAI,CAAC,aAAa,EAAE;YACtB,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,sBAAsB,CAAC;YAC5D,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,eA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AAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IACtE,CAAC;IAED,IAAW,iBAAiB;QAC1B,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,IAAI,EAAE,CAAC;QAE9D,OAAO,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CACpC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CACtF,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,IAAW,QAAQ;QACjB,IAAI,IAAI,CAAC,aAAa,EAAE;YACtB,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC;SACpC;aAAM;YACL,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;SACjC;IACH,CAAC;IAEO,eAAe,CAAC,SAAS,GAAG,GAAG;QACrC,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YACjC,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAC9D;aAAM;YACL,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SACjD;IACH,CAAC;CACF;AA3GD,oCA2GC","sourcesContent":["import * as path from 'path';\nimport { NgPackageConfig } from '../../../ng-package.schema';\nimport { CssUrl } from '../../styles/stylesheet-processor';\nimport { ensureUnixPath } from '../../utils/path';\n\n/** A list of output absolute paths for various formats */\nexport interface DestinationFiles {\n /** Absolute path of this entry point `declarations` */\n declarations: string;\n /** Absolute path of this entry point `FESM2020` module */\n fesm2020: string;\n /** Absolute path of this entry point `FESM2015` module */\n fesm2015: string;\n /** Absolute path of this entry point `ESM2020` module */\n esm2020: string;\n /** Sub path of entrypoint distributable. */\n directory: string;\n}\n\n/**\n * An entry point - quoting Angular Package Format - is:\n *\n * > a module intended to be imported by the user. It is referenced by a unique module ID and\n * > exports the public API referenced by that module ID. An example is `@angular/core` or\n * > `@angular/core/testing`. Both entry points exist in the `@angular/core` package, but they\n * > export different symbols. A package can have many entry points.\n *\n * #### Public API, source file tree and build output\n *\n * An entry point serves as the root of a source tree.\n * The entry point's public API references one TypeScript source file (`*.ts`).\n * That source file, e.g. `public_api.ts`, references other source files who in turn may reference\n * other source files, thus creating a tree of source code files.\n * The source files may be TypeScript (`*.ts`), Templates (`.html`) or Stylesheets\n * (`.css`, `.scss`, ..), or other formats.\n *\n * The compilation process for an entry point is a series of transformations applied to the source\n * files, e.g. TypeScript compilation, Inlining of Stylesheets and Templates, and so on.\n * As a result of the compilation process, an entry point is transpiled to a set of artefacts\n * (the build output) which include a FESM'15 Bundle, a FESM'5 Bundle, AoT metadata, TypeScript\n * type definitions, and so on.\n *\n * #### Representation in the domain\n *\n * The set of artefacts is reflected by `NgArtefacts`;\n * one `NgEntryPoint` relates to one `NgArtefacts`.\n * The parent package of an entry point is reflected by `NgPackage`.\n */\nexport class NgEntryPoint {\n constructor(\n /** Values from the `package.json` file of this entry point. */\n public readonly packageJson: Record<string, any>,\n /** Values from either the `ngPackage` option (from `package.json`) or values from `ng-package.json`. */\n public readonly ngPackageJson: NgPackageConfig,\n /** Absolute directory path of this entry point's `package.json` location. */\n public readonly basePath: string,\n /** XX: additional auto-configured data passed for secondary entry point's. Needs better docs. */\n private readonly secondaryData?: { [key: string]: any },\n ) {}\n\n /** Absolute file path of the entry point's source code entry file. */\n public get entryFilePath(): string {\n return path.resolve(this.basePath, this.entryFile);\n }\n\n /** Whether or not the entrypoint is secondary */\n public get isSecondaryEntryPoint(): boolean {\n return !!this.secondaryData;\n }\n\n /** Absolute directory path of this entry point's 'package.json'. */\n public get destinationPath(): string {\n if (this.secondaryData) {\n return this.secondaryData.destinationPath;\n } else {\n return path.resolve(this.basePath, this.$get('dest'));\n }\n }\n\n public get destinationFiles(): DestinationFiles {\n let primaryDestPath = this.destinationPath;\n let secondaryDir = '';\n\n if (this.secondaryData) {\n primaryDestPath = this.secondaryData.primaryDestinationPath;\n secondaryDir = path.relative(primaryDestPath, this.secondaryData.destinationPath);\n }\n\n const flatModuleFile = this.flatModuleFile;\n const pathJoinWithDest = (...paths: string[]) => path.join(primaryDestPath, ...paths);\n\n return {\n directory: ensureUnixPath(secondaryDir),\n declarations: pathJoinWithDest(secondaryDir, 'index.d.ts'),\n esm2020: pathJoinWithDest('esm2020', secondaryDir, `${flatModuleFile}.mjs`),\n fesm2020: pathJoinWithDest('fesm2020', `${flatModuleFile}.mjs`),\n fesm2015: pathJoinWithDest('fesm2015', `${flatModuleFile}.mjs`),\n };\n }\n\n public $get(key: string): any {\n const parts = key.split('.');\n let value = this.ngPackageJson as unknown;\n for (const key of parts) {\n if (typeof value === 'object' && key in value) {\n value = value[key];\n } else {\n return undefined;\n }\n }\n\n return value;\n }\n\n public get entryFile(): string {\n // `./index.ts` -> `index.ts`\n return path.posix.normalize(this.$get('lib.entryFile'));\n }\n\n public get cssUrl(): CssUrl {\n return this.$get('lib.cssUrl');\n }\n\n public get flatModuleFile(): string {\n return this.$get('lib.flatModuleFile') || this.flattenModuleId('-');\n }\n\n public get styleIncludePaths(): string[] {\n const includePaths = this.$get('lib.styleIncludePaths') || [];\n\n return includePaths.map(includePath =>\n path.isAbsolute(includePath) ? includePath : path.resolve(this.basePath, includePath),\n );\n }\n\n /**\n * The module ID is an \"identifier of a module used in the import statements, e.g.\n * '@angular/core'. The ID often maps directly to a path on the filesystem, but this\n * is not always the case due to various module resolution strategies.\"\n */\n public get moduleId(): string {\n if (this.secondaryData) {\n return this.secondaryData.moduleId;\n } else {\n return this.packageJson['name'];\n }\n }\n\n private flattenModuleId(separator = '.') {\n if (this.moduleId.startsWith('@')) {\n return this.moduleId.substring(1).split('/').join(separator);\n } else {\n return this.moduleId.split('/').join(separator);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"entry-point.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/entry-point.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAG7B,2CAAkD;AAoBlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,YAAY;IACvB;IACE,+DAA+D;IAC/C,WAAgC;IAChD,wGAAwG;IACxF,aAA8B;IAC9C,6EAA6E;IAC7D,QAAgB;IAChC,iGAAiG;IAChF,aAAsC;QANvC,gBAAW,GAAX,WAAW,CAAqB;QAEhC,kBAAa,GAAb,aAAa,CAAiB;QAE9B,aAAQ,GAAR,QAAQ,CAAQ;QAEf,kBAAa,GAAb,aAAa,CAAyB;IACtD,CAAC;IAEJ,sEAAsE;IACtE,IAAW,aAAa;QACtB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACrD,CAAC;IAED,iDAAiD;IACjD,IAAW,qBAAqB;QAC9B,OAAO,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED,oEAAoE;IACpE,IAAW,eAAe;QACxB,IAAI,IAAI,CAAC,aAAa,EAAE;YACtB,OAAO,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC;SAC3C;aAAM;YACL,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;SACvD;IACH,CAAC;IAED,IAAW,gBAAgB;QACzB,IAAI,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC3C,IAAI,YAAY,GAAG,EAAE,CAAC;QAEtB,IAAI,IAAI,CAAC,aAAa,EAAE;YACtB,eAAe,GAAG,IAAI,CAA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l } from '../../styles/stylesheet-processor';\nimport { ensureUnixPath } from '../../utils/path';\n\n/** A list of output absolute paths for various formats */\nexport interface DestinationFiles {\n /** Absolute path of this entry point `declarations` */\n declarations: string;\n /** Absolute path of this entry point `FESM2020` module */\n fesm2020: string;\n /** Absolute path of this entry point `FESM2015` module */\n fesm2015: string;\n /** Absolute path of this entry point `ESM2020` module */\n esm2020: string;\n /** Sub path of entrypoint distributable. */\n directory: string;\n /** Absolute path of this entry point `FESM2020` directory */\n fesm2020Dir: string;\n /** Absolute path of this entry point `FESM2015` directory */\n fesm2015Dir: string;\n}\n\n/**\n * An entry point - quoting Angular Package Format - is:\n *\n * > a module intended to be imported by the user. It is referenced by a unique module ID and\n * > exports the public API referenced by that module ID. An example is `@angular/core` or\n * > `@angular/core/testing`. Both entry points exist in the `@angular/core` package, but they\n * > export different symbols. A package can have many entry points.\n *\n * #### Public API, source file tree and build output\n *\n * An entry point serves as the root of a source tree.\n * The entry point's public API references one TypeScript source file (`*.ts`).\n * That source file, e.g. `public_api.ts`, references other source files who in turn may reference\n * other source files, thus creating a tree of source code files.\n * The source files may be TypeScript (`*.ts`), Templates (`.html`) or Stylesheets\n * (`.css`, `.scss`, ..), or other formats.\n *\n * The compilation process for an entry point is a series of transformations applied to the source\n * files, e.g. TypeScript compilation, Inlining of Stylesheets and Templates, and so on.\n * As a result of the compilation process, an entry point is transpiled to a set of artefacts\n * (the build output) which include a FESM'15 Bundle, a FESM'5 Bundle, AoT metadata, TypeScript\n * type definitions, and so on.\n *\n * #### Representation in the domain\n *\n * The set of artefacts is reflected by `NgArtefacts`;\n * one `NgEntryPoint` relates to one `NgArtefacts`.\n * The parent package of an entry point is reflected by `NgPackage`.\n */\nexport class NgEntryPoint {\n constructor(\n /** Values from the `package.json` file of this entry point. */\n public readonly packageJson: Record<string, any>,\n /** Values from either the `ngPackage` option (from `package.json`) or values from `ng-package.json`. */\n public readonly ngPackageJson: NgPackageConfig,\n /** Absolute directory path of this entry point's `package.json` location. */\n public readonly basePath: string,\n /** XX: additional auto-configured data passed for secondary entry point's. Needs better docs. */\n private readonly secondaryData?: { [key: string]: any },\n ) {}\n\n /** Absolute file path of the entry point's source code entry file. */\n public get entryFilePath(): string {\n return path.resolve(this.basePath, this.entryFile);\n }\n\n /** Whether or not the entrypoint is secondary */\n public get isSecondaryEntryPoint(): boolean {\n return !!this.secondaryData;\n }\n\n /** Absolute directory path of this entry point's 'package.json'. */\n public get destinationPath(): string {\n if (this.secondaryData) {\n return this.secondaryData.destinationPath;\n } else {\n return path.resolve(this.basePath, this.$get('dest'));\n }\n }\n\n public get destinationFiles(): DestinationFiles {\n let primaryDestPath = this.destinationPath;\n let secondaryDir = '';\n\n if (this.secondaryData) {\n primaryDestPath = this.secondaryData.primaryDestinationPath;\n secondaryDir = path.relative(primaryDestPath, this.secondaryData.destinationPath);\n }\n\n const flatModuleFile = this.flatModuleFile;\n const pathJoinWithDest = (...paths: string[]) => path.join(primaryDestPath, ...paths);\n\n return {\n directory: ensureUnixPath(secondaryDir),\n declarations: pathJoinWithDest(secondaryDir, 'index.d.ts'),\n esm2020: pathJoinWithDest('esm2020', secondaryDir, `${flatModuleFile}.mjs`),\n fesm2020: pathJoinWithDest('fesm2020', `${flatModuleFile}.mjs`),\n fesm2015: pathJoinWithDest('fesm2015', `${flatModuleFile}.mjs`),\n fesm2020Dir: pathJoinWithDest('fesm2020'),\n fesm2015Dir: pathJoinWithDest('fesm2015'),\n };\n }\n\n public $get(key: string): any {\n const parts = key.split('.');\n let value = this.ngPackageJson as unknown;\n for (const key of parts) {\n if (typeof value === 'object' && key in value) {\n value = value[key];\n } else {\n return undefined;\n }\n }\n\n return value;\n }\n\n public get entryFile(): string {\n // `./index.ts` -> `index.ts`\n return path.posix.normalize(this.$get('lib.entryFile'));\n }\n\n public get cssUrl(): CssUrl {\n return this.$get('lib.cssUrl');\n }\n\n public get flatModuleFile(): string {\n return this.$get('lib.flatModuleFile') || this.flattenModuleId('-');\n }\n\n public get styleIncludePaths(): string[] {\n const includePaths = this.$get('lib.styleIncludePaths') || [];\n\n return includePaths.map(includePath =>\n path.isAbsolute(includePath) ? includePath : path.resolve(this.basePath, includePath),\n );\n }\n\n /**\n * The module ID is an \"identifier of a module used in the import statements, e.g.\n * '@angular/core'. The ID often maps directly to a path on the filesystem, but this\n * is not always the case due to various module resolution strategies.\"\n */\n public get moduleId(): string {\n if (this.secondaryData) {\n return this.secondaryData.moduleId;\n } else {\n return this.packageJson['name'];\n }\n }\n\n private flattenModuleId(separator = '.') {\n if (this.moduleId.startsWith('@')) {\n return this.moduleId.substring(1).split('/').join(separator);\n } else {\n return this.moduleId.split('/').join(separator);\n }\n }\n}\n"]}
@@ -15,29 +15,26 @@ const writeBundlesTransform = (options) => (0, transform_1.transformFromPromise)
15
15
  const entryPoint = graph.find((0, nodes_1.isEntryPointInProgress)());
16
16
  const { destinationFiles, entryPoint: ngEntryPoint, tsConfig } = entryPoint.data;
17
17
  const cache = entryPoint.cache;
18
- const { fesm2020, fesm2015, esm2020 } = destinationFiles;
18
+ const { fesm2020Dir, fesm2015Dir, esm2020 } = destinationFiles;
19
19
  const spinner = (0, ora_1.default)({
20
20
  hideCursor: false,
21
21
  discardStdin: false,
22
22
  });
23
- const key = await (0, cache_1.generateKey)(ngEntryPoint.moduleId, esm2020, 'fesm-bundles', tsConfig.options.compilationMode);
24
- const hash = await (0, cache_1.generateKey)(...[...cache.outputCache.values()].map(({ version }) => version));
23
+ const key = await (0, cache_1.generateKey)(ngEntryPoint.moduleId, esm2020, fesm2020Dir, fesm2015Dir, tsConfig.options.compilationMode);
24
+ const hash = await (0, cache_1.generateKey)([...cache.outputCache.values()].map(({ version }) => version).join(':'));
25
25
  const cacheDirectory = options.cacheEnabled && options.cacheDirectory;
26
26
  if (cacheDirectory) {
27
27
  const cacheResult = await (0, cache_1.readCacheEntry)(options.cacheDirectory, key);
28
28
  if ((cacheResult === null || cacheResult === void 0 ? void 0 : cacheResult.hash) === hash) {
29
29
  try {
30
30
  spinner.start('Writing FESM bundles');
31
- await Promise.all([
32
- (0, fs_1.mkdir)((0, path_1.dirname)(fesm2020), { recursive: true }),
33
- (0, fs_1.mkdir)((0, path_1.dirname)(fesm2015), { recursive: true }),
34
- ]);
35
- await Promise.all([
36
- (0, fs_1.writeFile)(fesm2020, cacheResult.fesm2020.code),
37
- (0, fs_1.writeFile)(`${fesm2020}.map`, JSON.stringify(cacheResult.fesm2020.map)),
38
- (0, fs_1.writeFile)(fesm2015, cacheResult.fesm2015.code),
39
- (0, fs_1.writeFile)(`${fesm2015}.map`, JSON.stringify(cacheResult.fesm2015.map)),
40
- ]);
31
+ await Promise.all([(0, fs_1.mkdir)(fesm2020Dir, { recursive: true }), (0, fs_1.mkdir)(fesm2015Dir, { recursive: true })]);
32
+ for (const file of cacheResult.fesm2020) {
33
+ await (0, fs_1.writeFile)((0, path_1.join)(fesm2020Dir, file.fileName), file.type === 'asset' ? file.source : file.code);
34
+ }
35
+ for (const file of cacheResult.fesm2015) {
36
+ await (0, fs_1.writeFile)((0, path_1.join)(fesm2015Dir, file.fileName), file.type === 'asset' ? file.source : file.code);
37
+ }
41
38
  spinner.succeed('Writing FESM bundles');
42
39
  }
43
40
  catch (error) {
@@ -47,29 +44,39 @@ const writeBundlesTransform = (options) => (0, transform_1.transformFromPromise)
47
44
  return;
48
45
  }
49
46
  }
50
- const fesmCache = {
51
- hash,
52
- };
53
- try {
54
- spinner.start('Generating FESM2020');
55
- const { cache: rollupFESMCache, code, map, } = await (0, rollup_1.rollupBundleFile)({
47
+ async function generateFESM(rollupCache, dir, downlevel) {
48
+ const { cache: rollupFESMCache, files } = await (0, rollup_1.rollupBundleFile)({
56
49
  sourceRoot: tsConfig.options.sourceRoot,
57
50
  entry: esm2020,
51
+ entryName: ngEntryPoint.flatModuleFile,
58
52
  moduleName: ngEntryPoint.moduleId,
59
- dest: fesm2020,
60
- cache: cache.rollupFESM2020Cache,
53
+ dir,
54
+ downlevel,
55
+ cache: rollupCache,
61
56
  cacheDirectory,
62
57
  fileCache: cache.outputCache,
63
- cacheKey: await (0, cache_1.generateKey)(esm2020, ngEntryPoint.moduleId, fesm2020, tsConfig.options.compilationMode),
58
+ cacheKey: await (0, cache_1.generateKey)(esm2020, dir, ngEntryPoint.moduleId, tsConfig.options.compilationMode),
64
59
  });
65
- fesmCache.fesm2020 = {
66
- code,
67
- map,
60
+ return {
61
+ /** The map contents are in an asset file type, which makes storing the map in the cache as redudant. */
62
+ files: files.map(f => {
63
+ if (f.type === 'chunk') {
64
+ f.map = null;
65
+ }
66
+ return f;
67
+ }),
68
+ rollupCache: options.watch ? rollupFESMCache : undefined,
68
69
  };
70
+ }
71
+ const fesmCache = {
72
+ hash,
73
+ };
74
+ try {
75
+ spinner.start('Generating FESM2020');
76
+ const { rollupCache, files } = await generateFESM(cache.rollupFESM2020Cache, fesm2020Dir, false);
77
+ cache.rollupFESM2020Cache = rollupCache;
78
+ fesmCache.fesm2020 = files;
69
79
  spinner.succeed();
70
- if (options.watch) {
71
- cache.rollupFESM2020Cache = rollupFESMCache;
72
- }
73
80
  }
74
81
  catch (error) {
75
82
  spinner.fail();
@@ -77,25 +84,10 @@ const writeBundlesTransform = (options) => (0, transform_1.transformFromPromise)
77
84
  }
78
85
  try {
79
86
  spinner.start('Generating FESM2015');
80
- const { cache: rollupFESMCache, code, map, } = await (0, rollup_1.rollupBundleFile)({
81
- sourceRoot: tsConfig.options.sourceRoot,
82
- entry: esm2020,
83
- moduleName: ngEntryPoint.moduleId,
84
- dest: fesm2015,
85
- downlevel: true,
86
- cache: cache.rollupFESM2015Cache,
87
- cacheDirectory,
88
- fileCache: cache.outputCache,
89
- cacheKey: await (0, cache_1.generateKey)(esm2020, ngEntryPoint.moduleId, fesm2015, tsConfig.options.compilationMode),
90
- });
91
- fesmCache.fesm2015 = {
92
- code,
93
- map,
94
- };
87
+ const { rollupCache, files } = await generateFESM(cache.rollupFESM2015Cache, fesm2015Dir, true);
88
+ cache.rollupFESM2015Cache = rollupCache;
89
+ fesmCache.fesm2015 = files;
95
90
  spinner.succeed();
96
- if (options.watch) {
97
- cache.rollupFESM2015Cache = rollupFESMCache;
98
- }
99
91
  }
100
92
  catch (error) {
101
93
  spinner.fail();
@@ -1 +1 @@
1
- {"version":3,"file":"write-bundles.transform.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/write-bundles.transform.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AACtB,+BAA+B;AAE/B,iDAAwD;AACxD,qDAA6D;AAC7D,6CAAgF;AAChF,uCAAkD;AAClD,oCAAkE;AAe3D,MAAM,qBAAqB,GAAG,CAAC,OAAyB,EAAE,EAAE,CACjE,IAAA,gCAAoB,EAAC,KAAK,EAAC,KAAK,EAAC,EAAE;IACjC,MAAM,UAAU,GAAmB,KAAK,CAAC,IAAI,CAAC,IAAA,8BAAsB,GAAE,CAAC,CAAC;IACxE,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC;IACjF,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;IAC/B,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC;IAEzD,MAAM,OAAO,GAAG,IAAA,aAAG,EAAC;QAClB,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,MAAM,IAAA,mBAAW,EAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAChH,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAW,EAAC,GAAG,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACjG,MAAM,cAAc,GAAG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AM,IAAA,mBAAW,EAAC,OAAO,EAAE,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,eAAe,CAAC;SACxG,CAAC,CAAC;QAEH,SAAS,CAAC,QAAQ,GAAG;YACnB,IAAI;YACJ,GAAG;SACJ,CAAC;QAEF,OAAO,CAAC,OAAO,EAAE,CAAC;QAElB,IAAI,OAAO,CAAC,KAAK,EAAE;YACjB,KAAK,CAAC,mBAAmB,GAAG,eAAe,CAAC;SAC7C;KACF;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,IAAI,EAAE,CAAC;QACf,MAAM,KAAK,CAAC;KACb;IAED,IAAI,cAAc,EAAE;QAClB,MAAM,IAAA,sBAAc,EAAC,cAAc,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;KACtE;AACH,CAAC,CAAC,CAAC;AAnHQ,QAAA,qBAAqB,yBAmH7B","sourcesContent":["import ora from 'ora';\nimport { dirname } from 'path';\nimport { SourceMap } from 'rollup';\nimport { rollupBundleFile } from '../../flatten/rollup';\nimport { transformFromPromise } from '../../graph/transform';\nimport { generateKey, readCacheEntry, saveCacheEntry } from '../../utils/cache';\nimport { mkdir, writeFile } from '../../utils/fs';\nimport { EntryPointNode, isEntryPointInProgress } from '../nodes';\nimport { NgPackagrOptions } from '../options.di';\n\ninterface BundlesCache {\n hash: string;\n fesm2020: {\n code: string;\n map: SourceMap;\n };\n fesm2015: {\n code: string;\n map: SourceMap;\n };\n}\n\nexport const writeBundlesTransform = (options: NgPackagrOptions) =>\n transformFromPromise(async graph => {\n const entryPoint: EntryPointNode = graph.find(isEntryPointInProgress());\n const { destinationFiles, entryPoint: ngEntryPoint, tsConfig } = entryPoint.data;\n const cache = entryPoint.cache;\n const { fesm2020, fesm2015, esm2020 } = destinationFiles;\n\n const spinner = ora({\n hideCursor: false,\n discardStdin: false,\n });\n\n const key = await generateKey(ngEntryPoint.moduleId, esm2020, 'fesm-bundles', tsConfig.options.compilationMode);\n const hash = await generateKey(...[...cache.outputCache.values()].map(({ version }) => version));\n const cacheDirectory = options.cacheEnabled && options.cacheDirectory;\n if (cacheDirectory) {\n const cacheResult: BundlesCache = await readCacheEntry(options.cacheDirectory, key);\n\n if (cacheResult?.hash === hash) {\n try {\n spinner.start('Writing FESM bundles');\n await Promise.all([\n mkdir(dirname(fesm2020), { recursive: true }),\n mkdir(dirname(fesm2015), { recursive: true }),\n ]);\n\n await Promise.all([\n writeFile(fesm2020, cacheResult.fesm2020.code),\n writeFile(`${fesm2020}.map`, JSON.stringify(cacheResult.fesm2020.map)),\n writeFile(fesm2015, cacheResult.fesm2015.code),\n writeFile(`${fesm2015}.map`, JSON.stringify(cacheResult.fesm2015.map)),\n ]);\n\n spinner.succeed('Writing FESM bundles');\n } catch (error) {\n spinner.fail();\n throw error;\n }\n\n return;\n }\n }\n\n const fesmCache: Partial<BundlesCache> = {\n hash,\n };\n\n try {\n spinner.start('Generating FESM2020');\n const {\n cache: rollupFESMCache,\n code,\n map,\n } = await rollupBundleFile({\n sourceRoot: tsConfig.options.sourceRoot,\n entry: esm2020,\n moduleName: ngEntryPoint.moduleId,\n dest: fesm2020,\n cache: cache.rollupFESM2020Cache,\n cacheDirectory,\n fileCache: cache.outputCache,\n cacheKey: await generateKey(esm2020, ngEntryPoint.moduleId, fesm2020, tsConfig.options.compilationMode),\n });\n\n fesmCache.fesm2020 = {\n code,\n map,\n };\n\n spinner.succeed();\n\n if (options.watch) {\n cache.rollupFESM2020Cache = rollupFESMCache;\n }\n } catch (error) {\n spinner.fail();\n throw error;\n }\n\n try {\n spinner.start('Generating FESM2015');\n const {\n cache: rollupFESMCache,\n code,\n map,\n } = await rollupBundleFile({\n sourceRoot: tsConfig.options.sourceRoot,\n entry: esm2020,\n moduleName: ngEntryPoint.moduleId,\n dest: fesm2015,\n downlevel: true,\n cache: cache.rollupFESM2015Cache,\n cacheDirectory,\n fileCache: cache.outputCache,\n cacheKey: await generateKey(esm2020, ngEntryPoint.moduleId, fesm2015, tsConfig.options.compilationMode),\n });\n\n fesmCache.fesm2015 = {\n code,\n map,\n };\n\n spinner.succeed();\n\n if (options.watch) {\n cache.rollupFESM2015Cache = rollupFESMCache;\n }\n } catch (error) {\n spinner.fail();\n throw error;\n }\n\n if (cacheDirectory) {\n await saveCacheEntry(cacheDirectory, key, JSON.stringify(fesmCache));\n }\n });\n"]}
1
+ {"version":3,"file":"write-bundles.transform.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/write-bundles.transform.ts"],"names":[],"mappings":";;;;;;AAAA,8CAAsB;AACtB,+BAA4B;AAE5B,iDAAwD;AACxD,qDAA6D;AAC7D,6CAAgF;AAChF,uCAAkD;AAClD,oCAAkE;AAS3D,MAAM,qBAAqB,GAAG,CAAC,OAAyB,EAAE,EAAE,CACjE,IAAA,gCAAoB,EAAC,KAAK,EAAC,KAAK,EAAC,EAAE;IACjC,MAAM,UAAU,GAAmB,KAAK,CAAC,IAAI,CAAC,IAAA,8BAAsB,GAAE,CAAC,CAAC;IACxE,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC;IACjF,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;IAC/B,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC;IAE/D,MAAM,OAAO,GAAG,IAAA,aAAG,EAAC;QAClB,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,MAAM,IAAA,mBAAW,EAC3B,YAAY,CAAC,QAAQ,EACrB,OAAO,EACP,WAAW,EACX,WAAW,EACX,QAAQ,CAAC,OAAO,CAAC,eAAe,CACjC,CAAC;IACF,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAW,EAAC,CAAC,GAAG,KAAK,CAAC,WAAW,CAAC,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C,CAAC;QAEjG,KAAK,CAAC,mBAAmB,GAAG,WAAW,CAAC;QACxC,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC;QAE3B,OAAO,CAAC,OAAO,EAAE,CAAC;KACnB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,IAAI,EAAE,CAAC;QACf,MAAM,KAAK,CAAC;KACb;IAED,IAAI;QACF,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACrC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,mBAAmB,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;QAEhG,KAAK,CAAC,mBAAmB,GAAG,WAAW,CAAC;QACxC,SAAS,CAAC,QAAQ,GAAG,KAAK,CAAC;QAE3B,OAAO,CAAC,OAAO,EAAE,CAAC;KACnB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,IAAI,EAAE,CAAC;QACf,MAAM,KAAK,CAAC;KACb;IAED,IAAI,cAAc,EAAE;QAClB,MAAM,IAAA,sBAAc,EAAC,cAAc,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;KACtE;AACH,CAAC,CAAC,CAAC;AA/GQ,QAAA,qBAAqB,yBA+G7B","sourcesContent":["import ora from 'ora';\nimport { join } from 'path';\nimport { OutputAsset, OutputChunk, RollupCache } from 'rollup';\nimport { rollupBundleFile } from '../../flatten/rollup';\nimport { transformFromPromise } from '../../graph/transform';\nimport { generateKey, readCacheEntry, saveCacheEntry } from '../../utils/cache';\nimport { mkdir, writeFile } from '../../utils/fs';\nimport { EntryPointNode, isEntryPointInProgress } from '../nodes';\nimport { NgPackagrOptions } from '../options.di';\n\ninterface BundlesCache {\n hash: string;\n fesm2020: (OutputChunk | OutputAsset)[];\n fesm2015: (OutputChunk | OutputAsset)[];\n}\n\nexport const writeBundlesTransform = (options: NgPackagrOptions) =>\n transformFromPromise(async graph => {\n const entryPoint: EntryPointNode = graph.find(isEntryPointInProgress());\n const { destinationFiles, entryPoint: ngEntryPoint, tsConfig } = entryPoint.data;\n const cache = entryPoint.cache;\n const { fesm2020Dir, fesm2015Dir, esm2020 } = destinationFiles;\n\n const spinner = ora({\n hideCursor: false,\n discardStdin: false,\n });\n\n const key = await generateKey(\n ngEntryPoint.moduleId,\n esm2020,\n fesm2020Dir,\n fesm2015Dir,\n tsConfig.options.compilationMode,\n );\n const hash = await generateKey([...cache.outputCache.values()].map(({ version }) => version).join(':'));\n const cacheDirectory = options.cacheEnabled && options.cacheDirectory;\n if (cacheDirectory) {\n const cacheResult: BundlesCache = await readCacheEntry(options.cacheDirectory, key);\n\n if (cacheResult?.hash === hash) {\n try {\n spinner.start('Writing FESM bundles');\n await Promise.all([mkdir(fesm2020Dir, { recursive: true }), mkdir(fesm2015Dir, { recursive: true })]);\n\n for (const file of cacheResult.fesm2020) {\n await writeFile(join(fesm2020Dir, file.fileName), file.type === 'asset' ? file.source : file.code);\n }\n\n for (const file of cacheResult.fesm2015) {\n await writeFile(join(fesm2015Dir, file.fileName), file.type === 'asset' ? file.source : file.code);\n }\n\n spinner.succeed('Writing FESM bundles');\n } catch (error) {\n spinner.fail();\n throw error;\n }\n\n return;\n }\n }\n\n async function generateFESM(\n rollupCache: RollupCache,\n dir: string,\n downlevel: boolean,\n ): Promise<{ files: (OutputChunk | OutputAsset)[]; rollupCache: RollupCache }> {\n const { cache: rollupFESMCache, files } = await rollupBundleFile({\n sourceRoot: tsConfig.options.sourceRoot,\n entry: esm2020,\n entryName: ngEntryPoint.flatModuleFile,\n moduleName: ngEntryPoint.moduleId,\n dir,\n downlevel,\n cache: rollupCache,\n cacheDirectory,\n fileCache: cache.outputCache,\n cacheKey: await generateKey(esm2020, dir, ngEntryPoint.moduleId, tsConfig.options.compilationMode),\n });\n\n return {\n /** The map contents are in an asset file type, which makes storing the map in the cache as redudant. */\n files: files.map(f => {\n if (f.type === 'chunk') {\n f.map = null;\n }\n\n return f;\n }),\n rollupCache: options.watch ? rollupFESMCache : undefined,\n };\n }\n\n const fesmCache: Partial<BundlesCache> = {\n hash,\n };\n\n try {\n spinner.start('Generating FESM2020');\n const { rollupCache, files } = await generateFESM(cache.rollupFESM2020Cache, fesm2020Dir, false);\n\n cache.rollupFESM2020Cache = rollupCache;\n fesmCache.fesm2020 = files;\n\n spinner.succeed();\n } catch (error) {\n spinner.fail();\n throw error;\n }\n\n try {\n spinner.start('Generating FESM2015');\n const { rollupCache, files } = await generateFESM(cache.rollupFESM2015Cache, fesm2015Dir, true);\n\n cache.rollupFESM2015Cache = rollupCache;\n fesmCache.fesm2015 = files;\n\n spinner.succeed();\n } catch (error) {\n spinner.fail();\n throw error;\n }\n\n if (cacheDirectory) {\n await saveCacheEntry(cacheDirectory, key, JSON.stringify(fesmCache));\n }\n });\n"]}
@@ -52,37 +52,25 @@ const nodes_1 = require("./nodes");
52
52
  * @param entryPointTransform Transformation for asset rendering and compilation of a single entry point.
53
53
  */
54
54
  const packageTransformFactory = (project, options, initTsConfigTransform, analyseSourcesTransform, entryPointTransform) => (source$) => {
55
- const pkgUri = (0, nodes_1.ngUrl)(project);
55
+ log.info(`Building Angular Package`);
56
56
  const buildTransform = options.watch
57
57
  ? watchTransformFactory(project, options, analyseSourcesTransform, entryPointTransform)
58
58
  : buildTransformFactory(project, analyseSourcesTransform, entryPointTransform);
59
- return source$.pipe((0, operators_1.tap)(() => log.info(`Building Angular Package`)),
59
+ const pkgUri = (0, nodes_1.ngUrl)(project);
60
+ const ngPkg = new nodes_1.PackageNode(pkgUri);
61
+ return source$.pipe(
60
62
  // Discover packages and entry points
61
- (0, operators_1.switchMap)(graph => {
62
- const pkg = (0, discover_packages_1.discoverPackages)({ project });
63
- return (0, rxjs_1.from)(pkg).pipe((0, operators_1.map)(value => {
64
- const ngPkg = new nodes_1.PackageNode(pkgUri);
65
- ngPkg.data = value;
66
- return graph.put(ngPkg);
67
- }));
68
- }),
69
63
  // Clean the primary dest folder (should clean all secondary sub-directory, as well)
70
64
  (0, operators_1.switchMap)(async (graph) => {
71
- const { dest, deleteDestPath } = graph.get(pkgUri).data;
65
+ ngPkg.data = await (0, discover_packages_1.discoverPackages)({ project });
66
+ graph.put(ngPkg);
67
+ const { dest, deleteDestPath } = ngPkg.data;
72
68
  if (deleteDestPath) {
73
69
  try {
74
70
  await (0, fs_1.rmdir)(dest, { recursive: true });
75
71
  }
76
72
  catch { }
77
73
  }
78
- }, (graph, _) => graph),
79
- // Add entry points to graph
80
- (0, operators_1.map)(graph => {
81
- const foundNode = graph.get(pkgUri);
82
- if (!(0, nodes_1.isPackage)(foundNode)) {
83
- return graph;
84
- }
85
- const ngPkg = foundNode;
86
74
  const entryPoints = [ngPkg.data.primary, ...ngPkg.data.secondaries].map(entryPoint => {
87
75
  const { destinationFiles, moduleId } = entryPoint;
88
76
  const node = new nodes_1.EntryPointNode((0, nodes_1.ngUrl)(moduleId), ngPkg.cache.sourcesFileCache, ngPkg.cache.ngccProcessingCache, ngPkg.cache.moduleResolutionCache);
@@ -91,12 +79,20 @@ const packageTransformFactory = (project, options, initTsConfigTransform, analys
91
79
  ngPkg.dependsOn(node);
92
80
  return node;
93
81
  });
82
+ // Add entry points to graph
94
83
  return graph.put(entryPoints);
95
84
  }),
96
85
  // Initialize the tsconfig for each entry point
97
86
  initTsConfigTransform,
98
87
  // perform build
99
- buildTransform);
88
+ buildTransform, (0, rxjs_1.finalize)(() => {
89
+ var _a;
90
+ for (const node of ngPkg.dependents) {
91
+ if (node instanceof nodes_1.EntryPointNode) {
92
+ (_a = node.cache.stylesheetProcessor) === null || _a === void 0 ? void 0 : _a.destroy();
93
+ }
94
+ }
95
+ }));
100
96
  };
101
97
  exports.packageTransformFactory = packageTransformFactory;
102
98
  const watchTransformFactory = (project, _options, analyseSourcesTransform, entryPointTransform) => (source$) => {
@@ -145,7 +141,7 @@ const watchTransformFactory = (project, _options, analyseSourcesTransform, entry
145
141
  if (event === 'unlink' || event === 'add') {
146
142
  cache.globCache = regenerateGlobCache(sourcesFileCache);
147
143
  }
148
- }), (0, operators_1.debounceTime)(200), (0, operators_1.tap)(() => log.msg(FileChangeDetected)), (0, operators_1.startWith)(undefined), (0, operators_1.mapTo)(graph));
144
+ }), (0, operators_1.debounceTime)(200), (0, operators_1.tap)(() => log.msg(FileChangeDetected)), (0, operators_1.startWith)(undefined), (0, operators_1.map)(() => graph));
149
145
  }), (0, operators_1.switchMap)(graph => {
150
146
  return (0, rxjs_1.of)(graph).pipe(buildTransformFactory(project, analyseSourcesTransform, entryPointTransform), (0, operators_1.tap)(() => log.msg(CompleteWaitingForFileChange)), (0, operators_1.catchError)(error => {
151
147
  log.error(error);
@@ -192,7 +188,7 @@ const scheduleEntryPoints = (epTransform) => (0, rxjs_1.pipe)((0, operators_1.co
192
188
  // Build entry points with lower depth values first.
193
189
  return (0, rxjs_1.from)(groups).pipe((0, operators_1.map)((epUrl) => graph.find((0, nodes_1.byEntryPoint)().and(ep => ep.url === epUrl))), (0, operators_1.filter)((entryPoint) => entryPoint.state !== 'done'), (0, operators_1.concatMap)(ep => (0, rxjs_1.of)(ep).pipe(
194
190
  // Mark the entry point as 'in-progress'
195
- (0, operators_1.tap)(entryPoint => (entryPoint.state = node_1.STATE_IN_PROGRESS)), (0, operators_1.mapTo)(graph), epTransform)), (0, operators_1.takeLast)(1), // don't use last as sometimes it this will cause 'no elements in sequence',
191
+ (0, operators_1.tap)(entryPoint => (entryPoint.state = node_1.STATE_IN_PROGRESS)), (0, operators_1.map)(() => graph), epTransform)), (0, operators_1.takeLast)(1), // don't use last as sometimes it this will cause 'no elements in sequence',
196
192
  (0, operators_1.defaultIfEmpty)(graph));
197
193
  }));
198
194
  function regenerateGlobCache(sourcesFileCache) {
@@ -1 +1 @@
1
- {"version":3,"file":"package.transform.js","sourceRoot":"","sources":["../../../src/lib/ng-package/package.transform.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA4C;AAC5C,+BAAyE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AAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE;YACjD,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;SACrB;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { DepGraph } from 'dependency-graph';\nimport { NEVER, Observable, from, of as observableOf, pipe } from 'rxjs';\nimport {\n catchError,\n concatMap,\n debounceTime,\n defaultIfEmpty,\n filter,\n map,\n mapTo,\n startWith,\n switchMap,\n takeLast,\n tap,\n} from 'rxjs/operators';\nimport { FileCache } from '../file-system/file-cache';\nimport { createFileWatch } from '../file-system/file-watcher';\nimport { BuildGraph } from '../graph/build-graph';\nimport { STATE_IN_PROGRESS } from '../graph/node';\nimport { Transform } from '../graph/transform';\nimport { colors } from '../utils/color';\nimport { rmdir } from '../utils/fs';\nimport * as log from '../utils/log';\nimport { ensureUnixPath } from '../utils/path';\nimport { discoverPackages } from './discover-packages';\nimport {\n EntryPointNode,\n GlobCache,\n PackageNode,\n byEntryPoint,\n fileUrl,\n fileUrlPath,\n isEntryPoint,\n isPackage,\n ngUrl,\n} from './nodes';\nimport { NgPackagrOptions } from './options.di';\n\n/**\n * A transformation for building an npm package:\n *\n * - discoverPackages\n * - options\n * - initTsConfig\n * - analyzeTsSources (thereby extracting template and stylesheet files)\n * - for each entry point\n * - run the entryPontTransform\n *\n * @param project Project token, reference to `ng-package.json`\n * @param options ng-packagr options\n * @param initTsConfigTransform Transformation initializing the tsconfig of each entry point.\n * @param analyseSourcesTransform Transformation analyzing the typescript source files of each entry point.\n * @param entryPointTransform Transformation for asset rendering and compilation of a single entry point.\n */\nexport const packageTransformFactory =\n (\n project: string,\n options: NgPackagrOptions,\n initTsConfigTransform: Transform,\n analyseSourcesTransform: Transform,\n entryPointTransform: Transform,\n ) =>\n (source$: Observable<BuildGraph>): Observable<BuildGraph> => {\n const pkgUri = ngUrl(project);\n\n const buildTransform = options.watch\n ? watchTransformFactory(project, options, analyseSourcesTransform, entryPointTransform)\n : buildTransformFactory(project, analyseSourcesTransform, entryPointTransform);\n\n return source$.pipe(\n tap(() => log.info(`Building Angular Package`)),\n // Discover packages and entry points\n switchMap(graph => {\n const pkg = discoverPackages({ project });\n\n return from(pkg).pipe(\n map(value => {\n const ngPkg = new PackageNode(pkgUri);\n ngPkg.data = value;\n\n return graph.put(ngPkg);\n }),\n );\n }),\n // Clean the primary dest folder (should clean all secondary sub-directory, as well)\n switchMap(\n async graph => {\n const { dest, deleteDestPath } = graph.get(pkgUri).data;\n\n if (deleteDestPath) {\n try {\n await rmdir(dest, { recursive: true });\n } catch {}\n }\n },\n (graph, _) => graph,\n ),\n // Add entry points to graph\n map(graph => {\n const foundNode = graph.get(pkgUri);\n if (!isPackage(foundNode)) {\n return graph;\n }\n\n const ngPkg: PackageNode = foundNode;\n const entryPoints = [ngPkg.data.primary, ...ngPkg.data.secondaries].map(entryPoint => {\n const { destinationFiles, moduleId } = entryPoint;\n const node = new EntryPointNode(\n ngUrl(moduleId),\n ngPkg.cache.sourcesFileCache,\n ngPkg.cache.ngccProcessingCache,\n ngPkg.cache.moduleResolutionCache,\n );\n node.data = { entryPoint, destinationFiles };\n node.state = 'dirty';\n ngPkg.dependsOn(node);\n\n return node;\n });\n\n return graph.put(entryPoints);\n }),\n // Initialize the tsconfig for each entry point\n initTsConfigTransform,\n // perform build\n buildTransform,\n );\n };\n\nconst watchTransformFactory =\n (project: string, _options: NgPackagrOptions, analyseSourcesTransform: Transform, entryPointTransform: Transform) =>\n (source$: Observable<BuildGraph>): Observable<BuildGraph> => {\n const CompleteWaitingForFileChange = '\\nCompilation complete. Watching for file changes...';\n const FileChangeDetected = '\\nFile change detected. Starting incremental compilation...';\n const FailedWaitingForFileChange = '\\nCompilation failed. Watching for file changes...';\n\n return source$.pipe(\n switchMap(graph => {\n const { data, cache } = graph.find(isPackage);\n const { onFileChange, watcher } = createFileWatch([], [data.dest]);\n graph.watcher = watcher;\n\n return onFileChange.pipe(\n tap(fileChange => {\n const { filePath, event } = fileChange;\n const { sourcesFileCache } = cache;\n const cachedSourceFile = sourcesFileCache.get(filePath);\n const { declarationFileName } = cachedSourceFile || {};\n const uriToClean = [filePath, declarationFileName].map(x => fileUrl(ensureUnixPath(x)));\n const nodesToClean = graph.filter(node => uriToClean.some(uri => uri === node.url));\n\n if (!cachedSourceFile) {\n if (event === 'unlink' || event === 'add') {\n cache.globCache = regenerateGlobCache(sourcesFileCache);\n }\n\n if (!nodesToClean) {\n return;\n }\n }\n\n const allNodesToClean = [\n ...nodesToClean,\n // if a non ts file changes we need to clean up its direct dependees\n // this is mainly done for resources such as html and css\n ...nodesToClean.filter(node => !node.url.endsWith('.ts')).flatMap(node => [...node.dependees]),\n ];\n\n // delete node that changes\n for (const { url } of allNodesToClean) {\n sourcesFileCache.delete(fileUrlPath(url));\n }\n\n for (const entryPoint of graph.filter(isEntryPoint)) {\n const isDirty = [...allNodesToClean].some(dependent => entryPoint.dependents.has(dependent));\n if (isDirty) {\n entryPoint.state = 'dirty';\n\n uriToClean.forEach(url => {\n entryPoint.cache.analysesSourcesFileCache.delete(fileUrlPath(url));\n });\n }\n }\n\n // Regenerate glob cache\n if (event === 'unlink' || event === 'add') {\n cache.globCache = regenerateGlobCache(sourcesFileCache);\n }\n }),\n debounceTime(200),\n tap(() => log.msg(FileChangeDetected)),\n startWith(undefined),\n mapTo(graph),\n );\n }),\n switchMap(graph => {\n return observableOf(graph).pipe(\n buildTransformFactory(project, analyseSourcesTransform, entryPointTransform),\n tap(() => log.msg(CompleteWaitingForFileChange)),\n catchError(error => {\n log.error(error);\n log.msg(FailedWaitingForFileChange);\n\n return NEVER;\n }),\n );\n }),\n );\n };\n\nconst buildTransformFactory =\n (project: string, analyseSourcesTransform: Transform, entryPointTransform: Transform) =>\n (source$: Observable<BuildGraph>): Observable<BuildGraph> => {\n const startTime = Date.now();\n\n const pkgUri = ngUrl(project);\n\n return source$.pipe(\n // Analyse dependencies and external resources for each entry point\n analyseSourcesTransform,\n // Next, run through the entry point transformation (assets rendering, code compilation)\n scheduleEntryPoints(entryPointTransform),\n tap(graph => {\n const ngPkg = graph.get(pkgUri);\n log.success('\\n------------------------------------------------------------------------------');\n log.success(`Built Angular Package\n - from: ${ngPkg.data.src}\n - to: ${ngPkg.data.dest}`);\n log.success('------------------------------------------------------------------------------');\n const b = colors.bold;\n const w = colors.white;\n log.msg(w(`\\nBuild at: ${b(new Date().toISOString())} - Time: ${b('' + (Date.now() - startTime))}ms\\n`));\n }),\n );\n };\n\nconst scheduleEntryPoints = (epTransform: Transform): Transform =>\n pipe(\n concatMap(graph => {\n // Calculate node/dependency depth and determine build order\n const depGraph = new DepGraph({ circular: false });\n const entryPoints: EntryPointNode[] = graph.filter(isEntryPoint);\n\n for (const entryPoint of entryPoints) {\n // Remove `ng://` prefix for better error messages\n const from = entryPoint.url.substring(5);\n depGraph.addNode(from);\n\n for (const { url } of entryPoint.filter(isEntryPoint)) {\n const to = url.substring(5);\n depGraph.addNode(to);\n depGraph.addDependency(from, to);\n }\n }\n\n // The array index is the depth.\n const groups = depGraph.overallOrder().map(ngUrl);\n\n // Build entry points with lower depth values first.\n return from(groups).pipe(\n map((epUrl: string): EntryPointNode => graph.find(byEntryPoint().and(ep => ep.url === epUrl))),\n filter((entryPoint: EntryPointNode): boolean => entryPoint.state !== 'done'),\n concatMap(ep =>\n observableOf(ep).pipe(\n // Mark the entry point as 'in-progress'\n tap(entryPoint => (entryPoint.state = STATE_IN_PROGRESS)),\n mapTo(graph),\n epTransform,\n ),\n ),\n takeLast(1), // don't use last as sometimes it this will cause 'no elements in sequence',\n defaultIfEmpty(graph),\n );\n }),\n );\n\nfunction regenerateGlobCache(sourcesFileCache: FileCache): GlobCache {\n const cache: GlobCache = {};\n sourcesFileCache.forEach((value, key) => {\n // ignore node_modules and file which don't exists as they are not used by globbing in our case\n if (value.exists && !key.includes('node_modules')) {\n cache[key] = 'FILE';\n }\n });\n\n return cache;\n}\n"]}
1
+ {"version":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ph } from 'dependency-graph';\nimport { NEVER, Observable, finalize, from, of as observableOf, pipe } from 'rxjs';\nimport {\n catchError,\n concatMap,\n debounceTime,\n defaultIfEmpty,\n filter,\n map,\n startWith,\n switchMap,\n takeLast,\n tap,\n} from 'rxjs/operators';\nimport { FileCache } from '../file-system/file-cache';\nimport { createFileWatch } from '../file-system/file-watcher';\nimport { BuildGraph } from '../graph/build-graph';\nimport { STATE_IN_PROGRESS } from '../graph/node';\nimport { Transform } from '../graph/transform';\nimport { colors } from '../utils/color';\nimport { rmdir } from '../utils/fs';\nimport * as log from '../utils/log';\nimport { ensureUnixPath } from '../utils/path';\nimport { discoverPackages } from './discover-packages';\nimport {\n EntryPointNode,\n GlobCache,\n PackageNode,\n byEntryPoint,\n fileUrl,\n fileUrlPath,\n isEntryPoint,\n isPackage,\n ngUrl,\n} from './nodes';\nimport { NgPackagrOptions } from './options.di';\n\n/**\n * A transformation for building an npm package:\n *\n * - discoverPackages\n * - options\n * - initTsConfig\n * - analyzeTsSources (thereby extracting template and stylesheet files)\n * - for each entry point\n * - run the entryPontTransform\n *\n * @param project Project token, reference to `ng-package.json`\n * @param options ng-packagr options\n * @param initTsConfigTransform Transformation initializing the tsconfig of each entry point.\n * @param analyseSourcesTransform Transformation analyzing the typescript source files of each entry point.\n * @param entryPointTransform Transformation for asset rendering and compilation of a single entry point.\n */\nexport const packageTransformFactory =\n (\n project: string,\n options: NgPackagrOptions,\n initTsConfigTransform: Transform,\n analyseSourcesTransform: Transform,\n entryPointTransform: Transform,\n ) =>\n (source$: Observable<BuildGraph>): Observable<BuildGraph> => {\n log.info(`Building Angular Package`);\n\n const buildTransform = options.watch\n ? watchTransformFactory(project, options, analyseSourcesTransform, entryPointTransform)\n : buildTransformFactory(project, analyseSourcesTransform, entryPointTransform);\n\n const pkgUri = ngUrl(project);\n const ngPkg = new PackageNode(pkgUri);\n\n return source$.pipe(\n // Discover packages and entry points\n // Clean the primary dest folder (should clean all secondary sub-directory, as well)\n switchMap(async graph => {\n ngPkg.data = await discoverPackages({ project });\n\n graph.put(ngPkg);\n const { dest, deleteDestPath } = ngPkg.data;\n\n if (deleteDestPath) {\n try {\n await rmdir(dest, { recursive: true });\n } catch {}\n }\n\n const entryPoints = [ngPkg.data.primary, ...ngPkg.data.secondaries].map(entryPoint => {\n const { destinationFiles, moduleId } = entryPoint;\n const node = new EntryPointNode(\n ngUrl(moduleId),\n ngPkg.cache.sourcesFileCache,\n ngPkg.cache.ngccProcessingCache,\n ngPkg.cache.moduleResolutionCache,\n );\n node.data = { entryPoint, destinationFiles };\n node.state = 'dirty';\n ngPkg.dependsOn(node);\n\n return node;\n });\n\n // Add entry points to graph\n return graph.put(entryPoints);\n }),\n // Initialize the tsconfig for each entry point\n initTsConfigTransform,\n // perform build\n buildTransform,\n finalize(() => {\n for (const node of ngPkg.dependents) {\n if (node instanceof EntryPointNode) {\n node.cache.stylesheetProcessor?.destroy();\n }\n }\n }),\n );\n };\n\nconst watchTransformFactory =\n (project: string, _options: NgPackagrOptions, analyseSourcesTransform: Transform, entryPointTransform: Transform) =>\n (source$: Observable<BuildGraph>): Observable<BuildGraph> => {\n const CompleteWaitingForFileChange = '\\nCompilation complete. Watching for file changes...';\n const FileChangeDetected = '\\nFile change detected. Starting incremental compilation...';\n const FailedWaitingForFileChange = '\\nCompilation failed. Watching for file changes...';\n\n return source$.pipe(\n switchMap(graph => {\n const { data, cache } = graph.find(isPackage);\n const { onFileChange, watcher } = createFileWatch([], [data.dest]);\n graph.watcher = watcher;\n\n return onFileChange.pipe(\n tap(fileChange => {\n const { filePath, event } = fileChange;\n const { sourcesFileCache } = cache;\n const cachedSourceFile = sourcesFileCache.get(filePath);\n const { declarationFileName } = cachedSourceFile || {};\n const uriToClean = [filePath, declarationFileName].map(x => fileUrl(ensureUnixPath(x)));\n const nodesToClean = graph.filter(node => uriToClean.some(uri => uri === node.url));\n\n if (!cachedSourceFile) {\n if (event === 'unlink' || event === 'add') {\n cache.globCache = regenerateGlobCache(sourcesFileCache);\n }\n\n if (!nodesToClean) {\n return;\n }\n }\n\n const allNodesToClean = [\n ...nodesToClean,\n // if a non ts file changes we need to clean up its direct dependees\n // this is mainly done for resources such as html and css\n ...nodesToClean.filter(node => !node.url.endsWith('.ts')).flatMap(node => [...node.dependees]),\n ];\n\n // delete node that changes\n for (const { url } of allNodesToClean) {\n sourcesFileCache.delete(fileUrlPath(url));\n }\n\n for (const entryPoint of graph.filter(isEntryPoint)) {\n const isDirty = [...allNodesToClean].some(dependent => entryPoint.dependents.has(dependent));\n if (isDirty) {\n entryPoint.state = 'dirty';\n\n uriToClean.forEach(url => {\n entryPoint.cache.analysesSourcesFileCache.delete(fileUrlPath(url));\n });\n }\n }\n\n // Regenerate glob cache\n if (event === 'unlink' || event === 'add') {\n cache.globCache = regenerateGlobCache(sourcesFileCache);\n }\n }),\n debounceTime(200),\n tap(() => log.msg(FileChangeDetected)),\n startWith(undefined),\n map(() => graph),\n );\n }),\n switchMap(graph => {\n return observableOf(graph).pipe(\n buildTransformFactory(project, analyseSourcesTransform, entryPointTransform),\n tap(() => log.msg(CompleteWaitingForFileChange)),\n catchError(error => {\n log.error(error);\n log.msg(FailedWaitingForFileChange);\n\n return NEVER;\n }),\n );\n }),\n );\n };\n\nconst buildTransformFactory =\n (project: string, analyseSourcesTransform: Transform, entryPointTransform: Transform) =>\n (source$: Observable<BuildGraph>): Observable<BuildGraph> => {\n const startTime = Date.now();\n\n const pkgUri = ngUrl(project);\n\n return source$.pipe(\n // Analyse dependencies and external resources for each entry point\n analyseSourcesTransform,\n // Next, run through the entry point transformation (assets rendering, code compilation)\n scheduleEntryPoints(entryPointTransform),\n tap(graph => {\n const ngPkg = graph.get(pkgUri);\n log.success('\\n------------------------------------------------------------------------------');\n log.success(`Built Angular Package\n - from: ${ngPkg.data.src}\n - to: ${ngPkg.data.dest}`);\n log.success('------------------------------------------------------------------------------');\n const b = colors.bold;\n const w = colors.white;\n log.msg(w(`\\nBuild at: ${b(new Date().toISOString())} - Time: ${b('' + (Date.now() - startTime))}ms\\n`));\n }),\n );\n };\n\nconst scheduleEntryPoints = (epTransform: Transform): Transform =>\n pipe(\n concatMap(graph => {\n // Calculate node/dependency depth and determine build order\n const depGraph = new DepGraph({ circular: false });\n const entryPoints: EntryPointNode[] = graph.filter(isEntryPoint);\n\n for (const entryPoint of entryPoints) {\n // Remove `ng://` prefix for better error messages\n const from = entryPoint.url.substring(5);\n depGraph.addNode(from);\n\n for (const { url } of entryPoint.filter(isEntryPoint)) {\n const to = url.substring(5);\n depGraph.addNode(to);\n depGraph.addDependency(from, to);\n }\n }\n\n // The array index is the depth.\n const groups = depGraph.overallOrder().map(ngUrl);\n\n // Build entry points with lower depth values first.\n return from(groups).pipe(\n map((epUrl: string): EntryPointNode => graph.find(byEntryPoint().and(ep => ep.url === epUrl))),\n filter((entryPoint: EntryPointNode): boolean => entryPoint.state !== 'done'),\n concatMap(ep =>\n observableOf(ep).pipe(\n // Mark the entry point as 'in-progress'\n tap(entryPoint => (entryPoint.state = STATE_IN_PROGRESS)),\n map(() => graph),\n epTransform,\n ),\n ),\n takeLast(1), // don't use last as sometimes it this will cause 'no elements in sequence',\n defaultIfEmpty(graph),\n );\n }),\n );\n\nfunction regenerateGlobCache(sourcesFileCache: FileCache): GlobCache {\n const cache: GlobCache = {};\n sourcesFileCache.forEach((value, key) => {\n // ignore node_modules and file which don't exists as they are not used by globbing in our case\n if (value.exists && !key.includes('node_modules')) {\n cache[key] = 'FILE';\n }\n });\n\n return cache;\n}\n"]}
@@ -0,0 +1,11 @@
1
+ interface RenderRequest {
2
+ content: string;
3
+ filePath: string;
4
+ }
5
+ declare function render({ content, filePath }: RenderRequest): Promise<string>;
6
+ /**
7
+ * The default export will be the promise returned by the initialize function.
8
+ * This is awaited by piscina prior to using the Worker.
9
+ */
10
+ declare const _default: Promise<typeof render>;
11
+ export default _default;
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const autoprefixer_1 = __importDefault(require("autoprefixer"));
30
+ const node_path_1 = require("node:path");
31
+ const node_url_1 = require("node:url");
32
+ const node_worker_threads_1 = require("node:worker_threads");
33
+ const postcss_1 = __importDefault(require("postcss"));
34
+ const postcss_url_1 = __importDefault(require("postcss-url"));
35
+ const esbuild_executor_1 = require("../esbuild/esbuild-executor");
36
+ const cache_1 = require("../utils/cache");
37
+ const log = __importStar(require("../utils/log"));
38
+ const stylesheet_processor_1 = require("./stylesheet-processor");
39
+ const { tailwindConfigPath, projectBasePath, browserslistData, targets, cssUrl, styleIncludePaths } = node_worker_threads_1.workerData;
40
+ let cacheDirectory = node_worker_threads_1.workerData.cacheDirectory;
41
+ let postCssProcessor;
42
+ let esbuild;
43
+ async function render({ content, filePath }) {
44
+ let key;
45
+ if (cacheDirectory && !content.includes('@import') && !content.includes('@use')) {
46
+ // No transitive deps, we can cache more aggressively.
47
+ key = await (0, cache_1.generateKey)(content, ...browserslistData);
48
+ const result = await (0, cache_1.readCacheEntry)(cacheDirectory, key);
49
+ if (result) {
50
+ result.warnings.forEach(msg => log.warn(msg));
51
+ return result.css;
52
+ }
53
+ }
54
+ // Render pre-processor language (sass, styl, less)
55
+ const renderedCss = await renderCss(filePath, content);
56
+ // We cannot cache CSS re-rendering phase, because a transitive dependency via (@import) can case different CSS output.
57
+ // Example a change in a mixin or SCSS variable.
58
+ if (!key) {
59
+ key = await (0, cache_1.generateKey)(renderedCss, ...browserslistData);
60
+ }
61
+ if (cacheDirectory) {
62
+ const cachedResult = await (0, cache_1.readCacheEntry)(cacheDirectory, key);
63
+ if (cachedResult) {
64
+ cachedResult.warnings.forEach(msg => log.warn(msg));
65
+ return cachedResult.css;
66
+ }
67
+ }
68
+ // Render postcss (autoprefixing and friends)
69
+ const result = await postCssProcessor.process(renderedCss, {
70
+ from: filePath,
71
+ to: filePath.replace((0, node_path_1.extname)(filePath), '.css'),
72
+ });
73
+ const warnings = result.warnings().map(w => w.toString());
74
+ const { code, warnings: esBuildWarnings } = await esbuild.transform(result.css, {
75
+ loader: 'css',
76
+ minify: true,
77
+ target: targets,
78
+ sourcefile: filePath,
79
+ });
80
+ if (esBuildWarnings.length > 0) {
81
+ warnings.push(...(await esbuild.formatMessages(esBuildWarnings, { kind: 'warning' })));
82
+ }
83
+ if (cacheDirectory) {
84
+ await (0, cache_1.saveCacheEntry)(cacheDirectory, key, JSON.stringify({
85
+ css: code,
86
+ warnings,
87
+ }));
88
+ }
89
+ warnings.forEach(msg => log.warn(msg));
90
+ return code;
91
+ }
92
+ async function renderCss(filePath, css) {
93
+ const ext = (0, node_path_1.extname)(filePath);
94
+ switch (ext) {
95
+ case '.sass':
96
+ case '.scss': {
97
+ return (await Promise.resolve().then(() => __importStar(require('sass')))).compileString(css, {
98
+ url: (0, node_url_1.pathToFileURL)(filePath),
99
+ syntax: '.sass' === ext ? 'indented' : 'scss',
100
+ loadPaths: styleIncludePaths,
101
+ }).css;
102
+ }
103
+ case '.less': {
104
+ const { css: content } = await (await Promise.resolve().then(() => __importStar(require('less')))).default.render(css, {
105
+ filename: filePath,
106
+ math: 'always',
107
+ javascriptEnabled: true,
108
+ paths: styleIncludePaths,
109
+ });
110
+ return content;
111
+ }
112
+ case '.css':
113
+ default:
114
+ return css;
115
+ }
116
+ }
117
+ function getTailwindPlugin() {
118
+ // Attempt to setup Tailwind CSS
119
+ // Only load Tailwind CSS plugin if configuration file was found.
120
+ // This acts as a guard to ensure the project actually wants to use Tailwind CSS.
121
+ // The package may be unknowningly present due to a third-party transitive package dependency.
122
+ if (tailwindConfigPath) {
123
+ let tailwindPackagePath;
124
+ try {
125
+ tailwindPackagePath = require.resolve('tailwindcss', { paths: [projectBasePath] });
126
+ }
127
+ catch {
128
+ const relativeTailwindConfigPath = (0, node_path_1.relative)(projectBasePath, tailwindConfigPath);
129
+ log.warn(`Tailwind CSS configuration file found (${relativeTailwindConfigPath})` +
130
+ ` but the 'tailwindcss' package is not installed.` +
131
+ ` To enable Tailwind CSS, please install the 'tailwindcss' package.`);
132
+ }
133
+ if (tailwindPackagePath) {
134
+ return require(tailwindPackagePath)({ config: tailwindConfigPath });
135
+ }
136
+ }
137
+ }
138
+ async function initialize() {
139
+ const postCssPlugins = [];
140
+ const tailwinds = getTailwindPlugin();
141
+ if (tailwinds) {
142
+ postCssPlugins.push(tailwinds);
143
+ cacheDirectory = undefined;
144
+ }
145
+ if (cssUrl !== stylesheet_processor_1.CssUrl.none) {
146
+ postCssPlugins.push((0, postcss_url_1.default)({ url: cssUrl }));
147
+ }
148
+ postCssPlugins.push((0, autoprefixer_1.default)({
149
+ ignoreUnknownVersions: true,
150
+ overrideBrowserslist: browserslistData,
151
+ }));
152
+ postCssProcessor = (0, postcss_1.default)(postCssPlugins);
153
+ esbuild = new esbuild_executor_1.EsbuildExecutor();
154
+ // Return the render function for use
155
+ return render;
156
+ }
157
+ /**
158
+ * The default export will be the promise returned by the initialize function.
159
+ * This is awaited by piscina prior to using the Worker.
160
+ */
161
+ exports.default = initialize();
162
+ //# sourceMappingURL=stylesheet-processor-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stylesheet-processor-worker.js","sourceRoot":"","sources":["../../../src/lib/styles/stylesheet-processor-worker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAAwC;AACxC,yCAA8C;AAC9C,uCAAyC;AACzC,6DAAiD;AACjD,sDAA8B;AAC9B,8DAAqC;AACrC,kEAA8D;AAC9D,0CAA6E;AAC7E,kDAAoC;AACpC,iEAAgD;AAEhD,MAAM,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,GAAG,gCAQrG,CAAC;AAEF,IAAI,cAAc,GAAG,gCAAU,CAAC,cAAc,CAAC;AAC/C,IAAI,gBAA4C,CAAC;AACjD,IAAI,OAAwB,CAAC;AAO7B,KAAK,UAAU,MAAM,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAiB;IACxD,IAAI,GAAuB,CAAC;IAC5B,IAAI,cAAc,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC/E,sDAAsD;QACtD,GAAG,GAAG,MAAM,IAAA,mBAAW,EAAC,OAAO,EAAE,GAAG,gBAAgB,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,MAAM,IAAA,sBAAc,EAAC,cAAc,EAAE,GAAG,CAAC,CAAC;QACzD,IAAI,MAAM,EAAE;YACV,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAE9C,OAAO,MAAM,CAAC,GAAG,CAAC;SACnB;KACF;IAED,mDAAmD;IACnD,MA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CAAC","sourcesContent":["import autoprefixer from 'autoprefixer';\nimport { extname, relative } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport { workerData } from 'node:worker_threads';\nimport postcss from 'postcss';\nimport postcssUrl from 'postcss-url';\nimport { EsbuildExecutor } from '../esbuild/esbuild-executor';\nimport { generateKey, readCacheEntry, saveCacheEntry } from '../utils/cache';\nimport * as log from '../utils/log';\nimport { CssUrl } from './stylesheet-processor';\n\nconst { tailwindConfigPath, projectBasePath, browserslistData, targets, cssUrl, styleIncludePaths } = workerData as {\n tailwindConfigPath: string | undefined;\n browserslistData: string;\n targets: string[];\n projectBasePath: string;\n cssUrl: CssUrl;\n styleIncludePaths: string[];\n cacheDirectory: string | undefined;\n};\n\nlet cacheDirectory = workerData.cacheDirectory;\nlet postCssProcessor: ReturnType<typeof postcss>;\nlet esbuild: EsbuildExecutor;\n\ninterface RenderRequest {\n content: string;\n filePath: string;\n}\n\nasync function render({ content, filePath }: RenderRequest): Promise<string> {\n let key: string | undefined;\n if (cacheDirectory && !content.includes('@import') && !content.includes('@use')) {\n // No transitive deps, we can cache more aggressively.\n key = await generateKey(content, ...browserslistData);\n const result = await readCacheEntry(cacheDirectory, key);\n if (result) {\n result.warnings.forEach(msg => log.warn(msg));\n\n return result.css;\n }\n }\n\n // Render pre-processor language (sass, styl, less)\n const renderedCss = await renderCss(filePath, content);\n\n // We cannot cache CSS re-rendering phase, because a transitive dependency via (@import) can case different CSS output.\n // Example a change in a mixin or SCSS variable.\n if (!key) {\n key = await generateKey(renderedCss, ...browserslistData);\n }\n\n if (cacheDirectory) {\n const cachedResult = await readCacheEntry(cacheDirectory, key);\n if (cachedResult) {\n cachedResult.warnings.forEach(msg => log.warn(msg));\n\n return cachedResult.css;\n }\n }\n\n // Render postcss (autoprefixing and friends)\n const result = await postCssProcessor.process(renderedCss, {\n from: filePath,\n to: filePath.replace(extname(filePath), '.css'),\n });\n\n const warnings = result.warnings().map(w => w.toString());\n const { code, warnings: esBuildWarnings } = await esbuild.transform(result.css, {\n loader: 'css',\n minify: true,\n target: targets,\n sourcefile: filePath,\n });\n\n if (esBuildWarnings.length > 0) {\n warnings.push(...(await esbuild.formatMessages(esBuildWarnings, { kind: 'warning' })));\n }\n\n if (cacheDirectory) {\n await saveCacheEntry(\n cacheDirectory,\n key,\n JSON.stringify({\n css: code,\n warnings,\n }),\n );\n }\n\n warnings.forEach(msg => log.warn(msg));\n\n return code;\n}\n\nasync function renderCss(filePath: string, css: string): Promise<string> {\n const ext = extname(filePath);\n\n switch (ext) {\n case '.sass':\n case '.scss': {\n return (await import('sass')).compileString(css, {\n url: pathToFileURL(filePath),\n syntax: '.sass' === ext ? 'indented' : 'scss',\n loadPaths: styleIncludePaths,\n }).css;\n }\n case '.less': {\n const { css: content } = await (\n await import('less')\n ).default.render(css, {\n filename: filePath,\n math: 'always',\n javascriptEnabled: true,\n paths: styleIncludePaths,\n });\n\n return content;\n }\n\n case '.css':\n default:\n return css;\n }\n}\n\nfunction getTailwindPlugin() {\n // Attempt to setup Tailwind CSS\n // Only load Tailwind CSS plugin if configuration file was found.\n // This acts as a guard to ensure the project actually wants to use Tailwind CSS.\n // The package may be unknowningly present due to a third-party transitive package dependency.\n if (tailwindConfigPath) {\n let tailwindPackagePath;\n try {\n tailwindPackagePath = require.resolve('tailwindcss', { paths: [projectBasePath] });\n } catch {\n const relativeTailwindConfigPath = relative(projectBasePath, tailwindConfigPath);\n log.warn(\n `Tailwind CSS configuration file found (${relativeTailwindConfigPath})` +\n ` but the 'tailwindcss' package is not installed.` +\n ` To enable Tailwind CSS, please install the 'tailwindcss' package.`,\n );\n }\n\n if (tailwindPackagePath) {\n return require(tailwindPackagePath)({ config: tailwindConfigPath });\n }\n }\n}\n\nasync function initialize() {\n const postCssPlugins = [];\n const tailwinds = getTailwindPlugin();\n if (tailwinds) {\n postCssPlugins.push(tailwinds);\n cacheDirectory = undefined;\n }\n\n if (cssUrl !== CssUrl.none) {\n postCssPlugins.push(postcssUrl({ url: cssUrl }));\n }\n\n postCssPlugins.push(\n autoprefixer({\n ignoreUnknownVersions: true,\n overrideBrowserslist: browserslistData,\n }),\n );\n\n postCssProcessor = postcss(postCssPlugins);\n\n esbuild = new EsbuildExecutor();\n\n // Return the render function for use\n return render;\n}\n\n/**\n * The default export will be the promise returned by the initialize function.\n * This is awaited by piscina prior to using the Worker.\n */\nexport default initialize();\n"]}
@@ -2,28 +2,19 @@ export declare enum CssUrl {
2
2
  inline = "inline",
3
3
  none = "none"
4
4
  }
5
- export interface Result {
6
- css: string;
7
- warnings: string[];
8
- error?: string;
9
- }
10
5
  export declare class StylesheetProcessor {
11
6
  private readonly projectBasePath;
12
7
  private readonly basePath;
13
8
  private readonly cssUrl?;
14
9
  private readonly includePaths?;
15
- private cacheDirectory?;
16
- private browserslistData;
17
- private targets;
18
- private postCssProcessor;
19
- private esbuild;
20
- private styleIncludePaths;
21
- private readonly nodeModulesDirs;
10
+ private readonly cacheDirectory?;
11
+ private renderWorker;
22
12
  constructor(projectBasePath: string, basePath: string, cssUrl?: CssUrl, includePaths?: string[], cacheDirectory?: string | false);
23
13
  process({ filePath, content }: {
24
14
  filePath: string;
25
15
  content: string;
26
16
  }): Promise<string>;
27
- private createPostCssPlugins;
28
- private renderCss;
17
+ /** Destory workers in pool. */
18
+ destroy(): void;
19
+ private getOrCreateRenderWorker;
29
20
  }
@@ -1,42 +1,16 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
6
  exports.StylesheetProcessor = exports.CssUrl = void 0;
30
- const autoprefixer_1 = __importDefault(require("autoprefixer"));
31
7
  const browserslist_1 = __importDefault(require("browserslist"));
32
- const fs_1 = require("fs");
33
8
  const path_1 = require("path");
34
- const postcss_1 = __importDefault(require("postcss"));
35
- const postcss_url_1 = __importDefault(require("postcss-url"));
36
- const url_1 = require("url");
37
- const esbuild_executor_1 = require("../esbuild/esbuild-executor");
38
- const cache_1 = require("../utils/cache");
39
- const log = __importStar(require("../utils/log"));
9
+ const piscina_1 = __importDefault(require("piscina"));
10
+ const color_1 = require("../utils/color");
11
+ const fs_1 = require("../utils/fs");
12
+ const maxWorkersVariable = process.env['NG_BUILD_MAX_WORKERS'];
13
+ const maxThreads = typeof maxWorkersVariable === 'string' && maxWorkersVariable !== '' ? +maxWorkersVariable : 4;
40
14
  var CssUrl;
41
15
  (function (CssUrl) {
42
16
  CssUrl["inline"] = "inline";
@@ -49,9 +23,6 @@ class StylesheetProcessor {
49
23
  this.cssUrl = cssUrl;
50
24
  this.includePaths = includePaths;
51
25
  this.cacheDirectory = cacheDirectory;
52
- this.esbuild = new esbuild_executor_1.EsbuildExecutor();
53
- this.nodeModulesDirs = [];
54
- log.debug(`determine browserslist for ${this.basePath}`);
55
26
  // By default, browserslist defaults are too inclusive
56
27
  // https://github.com/browserslist/browserslist/blob/83764ea81ffaa39111c204b02c371afa44a4ff07/index.js#L516-L522
57
28
  // We change the default query to browsers that Angular support.
@@ -64,111 +35,49 @@ class StylesheetProcessor {
64
35
  'last 2 iOS major versions',
65
36
  'Firefox ESR',
66
37
  ];
67
- this.styleIncludePaths = [...this.includePaths];
38
+ }
39
+ async process({ filePath, content }) {
40
+ await this.getOrCreateRenderWorker();
41
+ return this.renderWorker.run({ content, filePath });
42
+ }
43
+ /** Destory workers in pool. */
44
+ destroy() {
45
+ var _a;
46
+ void ((_a = this.renderWorker) === null || _a === void 0 ? void 0 : _a.destroy());
47
+ }
48
+ async getOrCreateRenderWorker() {
49
+ if (this.renderWorker) {
50
+ return;
51
+ }
52
+ const styleIncludePaths = [...this.includePaths];
68
53
  let prevDir = null;
69
54
  let currentDir = this.basePath;
70
55
  while (currentDir !== prevDir) {
71
56
  const p = (0, path_1.join)(currentDir, 'node_modules');
72
- if ((0, fs_1.existsSync)(p)) {
73
- this.styleIncludePaths.push(p);
74
- this.nodeModulesDirs.push(p);
57
+ if (await (0, fs_1.exists)(p)) {
58
+ styleIncludePaths.push(p);
75
59
  }
76
60
  prevDir = currentDir;
77
61
  currentDir = (0, path_1.dirname)(prevDir);
78
62
  }
79
- this.browserslistData = (0, browserslist_1.default)(undefined, { path: this.basePath });
80
- this.targets = transformSupportedBrowsersToTargets(this.browserslistData);
81
- this.postCssProcessor = this.createPostCssPlugins();
82
- }
83
- async process({ filePath, content }) {
84
- let key;
85
- if (!content.includes('@import') && !content.includes('@use') && this.cacheDirectory) {
86
- // No transitive deps, we can cache more aggressively.
87
- key = await (0, cache_1.generateKey)(content, ...this.browserslistData);
88
- const result = await (0, cache_1.readCacheEntry)(this.cacheDirectory, key);
89
- if (result) {
90
- result.warnings.forEach(msg => log.warn(msg));
91
- return result.css;
92
- }
93
- }
94
- // Render pre-processor language (sass, styl, less)
95
- const renderedCss = await this.renderCss(filePath, content);
96
- // We cannot cache CSS re-rendering phase, because a transitive dependency via (@import) can case different CSS output.
97
- // Example a change in a mixin or SCSS variable.
98
- if (!key) {
99
- key = await (0, cache_1.generateKey)(renderedCss, ...this.browserslistData);
100
- }
101
- if (this.cacheDirectory) {
102
- const cachedResult = await (0, cache_1.readCacheEntry)(this.cacheDirectory, key);
103
- if (cachedResult) {
104
- cachedResult.warnings.forEach(msg => log.warn(msg));
105
- return cachedResult.css;
106
- }
107
- }
108
- // Render postcss (autoprefixing and friends)
109
- const result = await this.postCssProcessor.process(renderedCss, {
110
- from: filePath,
111
- to: filePath.replace((0, path_1.extname)(filePath), '.css'),
112
- });
113
- const warnings = result.warnings().map(w => w.toString());
114
- const { code, warnings: esBuildWarnings } = await this.esbuild.transform(result.css, {
115
- loader: 'css',
116
- minify: true,
117
- target: this.targets,
118
- sourcefile: filePath,
63
+ const browserslistData = (0, browserslist_1.default)(undefined, { path: this.basePath });
64
+ this.renderWorker = new piscina_1.default({
65
+ filename: require.resolve('./stylesheet-processor-worker'),
66
+ maxThreads,
67
+ env: {
68
+ ...process.env,
69
+ FORCE_COLOR: '' + color_1.colors.enabled,
70
+ },
71
+ workerData: {
72
+ tailwindConfigPath: await getTailwindConfigPath(this.projectBasePath),
73
+ projectBasePath: this.projectBasePath,
74
+ browserslistData,
75
+ targets: transformSupportedBrowsersToTargets(browserslistData),
76
+ cacheDirectory: this.cacheDirectory,
77
+ cssUrl: this.cssUrl,
78
+ styleIncludePaths: styleIncludePaths,
79
+ },
119
80
  });
120
- if (esBuildWarnings.length > 0) {
121
- warnings.push(...(await this.esbuild.formatMessages(esBuildWarnings, { kind: 'warning' })));
122
- }
123
- if (this.cacheDirectory) {
124
- await (0, cache_1.saveCacheEntry)(this.cacheDirectory, key, JSON.stringify({
125
- css: code,
126
- warnings,
127
- }));
128
- }
129
- warnings.forEach(msg => log.warn(msg));
130
- return code;
131
- }
132
- createPostCssPlugins() {
133
- const postCssPlugins = [];
134
- const tailwinds = getTailwindPlugin(this.projectBasePath);
135
- if (tailwinds) {
136
- postCssPlugins.push(tailwinds);
137
- this.cacheDirectory = false;
138
- }
139
- if (this.cssUrl !== CssUrl.none) {
140
- postCssPlugins.push((0, postcss_url_1.default)({ url: this.cssUrl }));
141
- }
142
- postCssPlugins.push((0, autoprefixer_1.default)({
143
- ignoreUnknownVersions: true,
144
- overrideBrowserslist: this.browserslistData,
145
- }));
146
- return (0, postcss_1.default)(postCssPlugins);
147
- }
148
- async renderCss(filePath, css) {
149
- const ext = (0, path_1.extname)(filePath);
150
- switch (ext) {
151
- case '.sass':
152
- case '.scss': {
153
- return (await Promise.resolve().then(() => __importStar(require('sass')))).compileString(css, {
154
- url: (0, url_1.pathToFileURL)(filePath),
155
- syntax: '.sass' === ext ? 'indented' : 'scss',
156
- loadPaths: this.styleIncludePaths,
157
- }).css;
158
- }
159
- case '.less': {
160
- const { css: content } = await (await Promise.resolve().then(() => __importStar(require('less')))).default.render(css, {
161
- filename: filePath,
162
- math: 'always',
163
- javascriptEnabled: true,
164
- paths: this.styleIncludePaths,
165
- });
166
- return content;
167
- }
168
- case '.css':
169
- default:
170
- return css;
171
- }
172
81
  }
173
82
  }
174
83
  exports.StylesheetProcessor = StylesheetProcessor;
@@ -196,29 +105,7 @@ function transformSupportedBrowsersToTargets(supportedBrowsers) {
196
105
  }
197
106
  return transformed.length ? transformed : undefined;
198
107
  }
199
- function getTailwindPlugin(projectBasePath) {
200
- // Attempt to setup Tailwind CSS
201
- // Only load Tailwind CSS plugin if configuration file was found.
202
- // This acts as a guard to ensure the project actually wants to use Tailwind CSS.
203
- // The package may be unknowningly present due to a third-party transitive package dependency.
204
- const tailwindConfigPath = getTailwindConfigPath(projectBasePath);
205
- if (tailwindConfigPath) {
206
- let tailwindPackagePath;
207
- try {
208
- tailwindPackagePath = require.resolve('tailwindcss', { paths: [projectBasePath] });
209
- }
210
- catch {
211
- const relativeTailwindConfigPath = (0, path_1.relative)(projectBasePath, tailwindConfigPath);
212
- log.warn(`Tailwind CSS configuration file found (${relativeTailwindConfigPath})` +
213
- ` but the 'tailwindcss' package is not installed.` +
214
- ` To enable Tailwind CSS, please install the 'tailwindcss' package.`);
215
- }
216
- if (tailwindPackagePath) {
217
- return require(tailwindPackagePath)({ config: tailwindConfigPath });
218
- }
219
- }
220
- }
221
- function getTailwindConfigPath(projectRoot) {
108
+ async function getTailwindConfigPath(projectRoot) {
222
109
  // A configuration file can exist in the project or workspace root
223
110
  // The list of valid config files can be found:
224
111
  // https://github.com/tailwindlabs/tailwindcss/blob/8845d112fb62d79815b50b3bae80c317450b8b92/src/util/resolveConfigPath.js#L46-L52
@@ -226,7 +113,7 @@ function getTailwindConfigPath(projectRoot) {
226
113
  for (const configFile of tailwindConfigFiles) {
227
114
  // Irrespective of the name project level configuration should always take precedence.
228
115
  const fullPath = (0, path_1.join)(projectRoot, configFile);
229
- if ((0, fs_1.existsSync)(fullPath)) {
116
+ if (await (0, fs_1.exists)(fullPath)) {
230
117
  return fullPath;
231
118
  }
232
119
  }
@@ -1 +1 @@
1
- {"version":3,"file":"stylesheet-processor.js","sourceRoot":"","sources":["../../../src/lib/styles/stylesheet-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAAwC;AACxC,gEAAwC;AACxC,2BAAgC;AAChC,+BAAwD;AACxD,sDAA8B;AAC9B,8DAAqC;AACrC,6BAAoC;AACpC,kEAA8D;AAC9D,0CAA6E;AAC7E,kDAAoC;AAEpC,IAAY,MAGX;AAHD,WAAY,MAAM;IAChB,2BAAiB,CAAA;IACjB,uBAAa,CAAA;AACf,CAAC,EAHW,MAAM,GAAN,cAAM,KAAN,cAAM,QAGjB;AAOD,MAAa,mBAAmB;IAQ9B,YACmB,eAAuB,EACvB,QAAgB,EAChB,MAAe,EACf,YAAuB,EAChC,cAA+B;QAJtB,oBAAe,GAAf,eAAe,CAAQ;QACvB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAS;QACf,iBAAY,GAAZ,YAAY,CAAW;QAChC,mBAAc,GAAd,cAAc,CAAiB;QATjC,YAAO,GAAG,IAAI,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AE,KAAK,EAAE,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;SACpF;QAAC,MAAM;YACN,MAAM,0BAA0B,GAAG,IAAA,eAAQ,EAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;YACjF,GAAG,CAAC,IAAI,CACN,0CAA0C,0BAA0B,GAAG;gBACrE,kDAAkD;gBAClD,oEAAoE,CACvE,CAAC;SACH;QACD,IAAI,mBAAmB,EAAE;YACvB,OAAO,OAAO,CAAC,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAC;SACrE;KACF;AACH,CAAC;AAED,SAAS,qBAAqB,CAAC,WAAmB;IAChD,kEAAkE;IAClE,+CAA+C;IAC/C,kIAAkI;IAClI,MAAM,mBAAmB,GAAG,CAAC,oBAAoB,EAAE,qBAAqB,CAAC,CAAC;IAC1E,KAAK,MAAM,UAAU,IAAI,mBAAmB,EAAE;QAC5C,sFAAsF;QACtF,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAC/C,IAAI,IAAA,eAAU,EAAC,QAAQ,CAAC,EAAE;YACxB,OAAO,QAAQ,CAAC;SACjB;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import autoprefixer from 'autoprefixer';\nimport browserslist from 'browserslist';\nimport { existsSync } from 'fs';\nimport { dirname, extname, join, relative } from 'path';\nimport postcss from 'postcss';\nimport postcssUrl from 'postcss-url';\nimport { pathToFileURL } from 'url';\nimport { EsbuildExecutor } from '../esbuild/esbuild-executor';\nimport { generateKey, readCacheEntry, saveCacheEntry } from '../utils/cache';\nimport * as log from '../utils/log';\n\nexport enum CssUrl {\n inline = 'inline',\n none = 'none',\n}\n\nexport interface Result {\n css: string;\n warnings: string[];\n error?: string;\n}\nexport class StylesheetProcessor {\n private browserslistData: string[];\n private targets: string[];\n private postCssProcessor: ReturnType<typeof postcss>;\n private esbuild = new EsbuildExecutor();\n private styleIncludePaths: string[];\n private readonly nodeModulesDirs = [];\n\n constructor(\n private readonly projectBasePath: string,\n private readonly basePath: string,\n private readonly cssUrl?: CssUrl,\n private readonly includePaths?: string[],\n private cacheDirectory?: string | false,\n ) {\n log.debug(`determine browserslist for ${this.basePath}`);\n // By default, browserslist defaults are too inclusive\n // https://github.com/browserslist/browserslist/blob/83764ea81ffaa39111c204b02c371afa44a4ff07/index.js#L516-L522\n\n // We change the default query to browsers that Angular support.\n // https://angular.io/guide/browser-support\n (browserslist.defaults as string[]) = [\n 'last 1 Chrome version',\n 'last 1 Firefox version',\n 'last 2 Edge major versions',\n 'last 2 Safari major versions',\n 'last 2 iOS major versions',\n 'Firefox ESR',\n ];\n\n this.styleIncludePaths = [...this.includePaths];\n let prevDir = null;\n let currentDir = this.basePath;\n\n while (currentDir !== prevDir) {\n const p = join(currentDir, 'node_modules');\n if (existsSync(p)) {\n this.styleIncludePaths.push(p);\n this.nodeModulesDirs.push(p);\n }\n\n prevDir = currentDir;\n currentDir = dirname(prevDir);\n }\n\n this.browserslistData = browserslist(undefined, { path: this.basePath });\n this.targets = transformSupportedBrowsersToTargets(this.browserslistData);\n this.postCssProcessor = this.createPostCssPlugins();\n }\n\n async process({ filePath, content }: { filePath: string; content: string }): Promise<string> {\n let key: string | undefined;\n\n if (!content.includes('@import') && !content.includes('@use') && this.cacheDirectory) {\n // No transitive deps, we can cache more aggressively.\n key = await generateKey(content, ...this.browserslistData);\n const result = await readCacheEntry(this.cacheDirectory, key);\n if (result) {\n result.warnings.forEach(msg => log.warn(msg));\n\n return result.css;\n }\n }\n\n // Render pre-processor language (sass, styl, less)\n const renderedCss = await this.renderCss(filePath, content);\n\n // We cannot cache CSS re-rendering phase, because a transitive dependency via (@import) can case different CSS output.\n // Example a change in a mixin or SCSS variable.\n if (!key) {\n key = await generateKey(renderedCss, ...this.browserslistData);\n }\n\n if (this.cacheDirectory) {\n const cachedResult = await readCacheEntry(this.cacheDirectory, key);\n if (cachedResult) {\n cachedResult.warnings.forEach(msg => log.warn(msg));\n\n return cachedResult.css;\n }\n }\n // Render postcss (autoprefixing and friends)\n const result = await this.postCssProcessor.process(renderedCss, {\n from: filePath,\n to: filePath.replace(extname(filePath), '.css'),\n });\n\n const warnings = result.warnings().map(w => w.toString());\n const { code, warnings: esBuildWarnings } = await this.esbuild.transform(result.css, {\n loader: 'css',\n minify: true,\n target: this.targets,\n sourcefile: filePath,\n });\n\n if (esBuildWarnings.length > 0) {\n warnings.push(...(await this.esbuild.formatMessages(esBuildWarnings, { kind: 'warning' })));\n }\n\n if (this.cacheDirectory) {\n await saveCacheEntry(\n this.cacheDirectory,\n key,\n JSON.stringify({\n css: code,\n warnings,\n }),\n );\n }\n warnings.forEach(msg => log.warn(msg));\n\n return code;\n }\n\n private createPostCssPlugins(): ReturnType<typeof postcss> {\n const postCssPlugins = [];\n const tailwinds = getTailwindPlugin(this.projectBasePath);\n if (tailwinds) {\n postCssPlugins.push(tailwinds);\n this.cacheDirectory = false;\n }\n\n if (this.cssUrl !== CssUrl.none) {\n postCssPlugins.push(postcssUrl({ url: this.cssUrl }));\n }\n\n postCssPlugins.push(\n autoprefixer({\n ignoreUnknownVersions: true,\n overrideBrowserslist: this.browserslistData,\n }),\n );\n\n return postcss(postCssPlugins);\n }\n\n private async renderCss(filePath: string, css: string): Promise<string> {\n const ext = extname(filePath);\n\n switch (ext) {\n case '.sass':\n case '.scss': {\n return (await import('sass')).compileString(css, {\n url: pathToFileURL(filePath),\n syntax: '.sass' === ext ? 'indented' : 'scss',\n loadPaths: this.styleIncludePaths,\n }).css;\n }\n case '.less': {\n const { css: content } = await (\n await import('less')\n ).default.render(css, {\n filename: filePath,\n math: 'always',\n javascriptEnabled: true,\n paths: this.styleIncludePaths,\n });\n\n return content;\n }\n\n case '.css':\n default:\n return css;\n }\n }\n}\n\nfunction transformSupportedBrowsersToTargets(supportedBrowsers: string[]): string[] {\n const transformed: string[] = [];\n\n // https://esbuild.github.io/api/#target\n const esBuildSupportedBrowsers = new Set(['safari', 'firefox', 'edge', 'chrome', 'ios']);\n\n for (const browser of supportedBrowsers) {\n let [browserName, version] = browser.split(' ');\n\n // browserslist uses the name `ios_saf` for iOS Safari whereas esbuild uses `ios`\n if (browserName === 'ios_saf') {\n browserName = 'ios';\n }\n\n // browserslist uses ranges `15.2-15.3` versions but only the lowest is required\n // to perform minimum supported feature checks. esbuild also expects a single version.\n [version] = version.split('-');\n\n if (esBuildSupportedBrowsers.has(browserName)) {\n if (browserName === 'safari' && version === 'TP') {\n // esbuild only supports numeric versions so `TP` is converted to a high number (999) since\n // a Technology Preview (TP) of Safari is assumed to support all currently known features.\n version = '999';\n }\n\n transformed.push(browserName + version);\n }\n }\n\n return transformed.length ? transformed : undefined;\n}\n\nfunction getTailwindPlugin(projectBasePath: string) {\n // Attempt to setup Tailwind CSS\n // Only load Tailwind CSS plugin if configuration file was found.\n // This acts as a guard to ensure the project actually wants to use Tailwind CSS.\n // The package may be unknowningly present due to a third-party transitive package dependency.\n const tailwindConfigPath = getTailwindConfigPath(projectBasePath);\n if (tailwindConfigPath) {\n let tailwindPackagePath;\n try {\n tailwindPackagePath = require.resolve('tailwindcss', { paths: [projectBasePath] });\n } catch {\n const relativeTailwindConfigPath = relative(projectBasePath, tailwindConfigPath);\n log.warn(\n `Tailwind CSS configuration file found (${relativeTailwindConfigPath})` +\n ` but the 'tailwindcss' package is not installed.` +\n ` To enable Tailwind CSS, please install the 'tailwindcss' package.`,\n );\n }\n if (tailwindPackagePath) {\n return require(tailwindPackagePath)({ config: tailwindConfigPath });\n }\n }\n}\n\nfunction getTailwindConfigPath(projectRoot: string): string | undefined {\n // A configuration file can exist in the project or workspace root\n // The list of valid config files can be found:\n // https://github.com/tailwindlabs/tailwindcss/blob/8845d112fb62d79815b50b3bae80c317450b8b92/src/util/resolveConfigPath.js#L46-L52\n const tailwindConfigFiles = ['tailwind.config.js', 'tailwind.config.cjs'];\n for (const configFile of tailwindConfigFiles) {\n // Irrespective of the name project level configuration should always take precedence.\n const fullPath = join(projectRoot, configFile);\n if (existsSync(fullPath)) {\n return fullPath;\n }\n }\n\n return undefined;\n}\n"]}
1
+ {"version":3,"file":"stylesheet-processor.js","sourceRoot":"","sources":["../../../src/lib/styles/stylesheet-processor.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAwC;AACxC,+BAAqC;AACrC,sDAA8B;AAC9B,0CAAwC;AACxC,oCAAqC;AAErC,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAC/D,MAAM,UAAU,GAAG,OAAO,kBAAkB,KAAK,QAAQ,IAAI,kBAAkB,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;AAEjH,IAAY,MAGX;AAHD,WAAY,MAAM;IAChB,2BAAiB,CAAA;IACjB,uBAAa,CAAA;AACf,CAAC,EAHW,MAAM,GAAN,cAAM,KAAN,cAAM,QAGjB;AAED,MAAa,mBAAmB;IAG9B,YACmB,eAAuB,EACvB,QAAgB,EAChB,MAAe,EACf,YAAuB,EACvB,cAA+B;QAJ/B,oBAAe,GAAf,eAAe,CAAQ;QACvB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAS;QACf,iBAAY,GAAZ,YAAY,CAAW;QACvB,mBAAc,GAAd,cAAc,CAAiB;QAEhD,sDAAsD;QACtD,gHAAgH;QAChH,gEAAgE;QAChE,2CAA2C;QAC1C,sBAAY,CAAC,QAAqB,GAAG;YACpC,uBAAuB;YACvB,wBAAwB;YACxB,4BAA4B;YAC5B,8BAA8B;YAC9B,2BAA2B;YAC3B,aAAa;SACd,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAyC;QACxE,MAAM,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAErC,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,C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QACtF,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,WAAW,EAAE,UAAU,CAAC,CAAC;QAC/C,IAAI,MAAM,IAAA,WAAM,EAAC,QAAQ,CAAC,EAAE;YAC1B,OAAO,QAAQ,CAAC;SACjB;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import browserslist from 'browserslist';\nimport { dirname, join } from 'path';\nimport Piscina from 'piscina';\nimport { colors } from '../utils/color';\nimport { exists } from '../utils/fs';\n\nconst maxWorkersVariable = process.env['NG_BUILD_MAX_WORKERS'];\nconst maxThreads = typeof maxWorkersVariable === 'string' && maxWorkersVariable !== '' ? +maxWorkersVariable : 4;\n\nexport enum CssUrl {\n inline = 'inline',\n none = 'none',\n}\n\nexport class StylesheetProcessor {\n private renderWorker: Piscina | undefined;\n\n constructor(\n private readonly projectBasePath: string,\n private readonly basePath: string,\n private readonly cssUrl?: CssUrl,\n private readonly includePaths?: string[],\n private readonly cacheDirectory?: string | false,\n ) {\n // By default, browserslist defaults are too inclusive\n // https://github.com/browserslist/browserslist/blob/83764ea81ffaa39111c204b02c371afa44a4ff07/index.js#L516-L522\n // We change the default query to browsers that Angular support.\n // https://angular.io/guide/browser-support\n (browserslist.defaults as string[]) = [\n 'last 1 Chrome version',\n 'last 1 Firefox version',\n 'last 2 Edge major versions',\n 'last 2 Safari major versions',\n 'last 2 iOS major versions',\n 'Firefox ESR',\n ];\n }\n\n async process({ filePath, content }: { filePath: string; content: string }): Promise<string> {\n await this.getOrCreateRenderWorker();\n\n return this.renderWorker.run({ content, filePath });\n }\n\n /** Destory workers in pool. */\n destroy(): void {\n void this.renderWorker?.destroy();\n }\n\n private async getOrCreateRenderWorker(): Promise<void> {\n if (this.renderWorker) {\n return;\n }\n\n const styleIncludePaths = [...this.includePaths];\n let prevDir = null;\n let currentDir = this.basePath;\n\n while (currentDir !== prevDir) {\n const p = join(currentDir, 'node_modules');\n if (await exists(p)) {\n styleIncludePaths.push(p);\n }\n\n prevDir = currentDir;\n currentDir = dirname(prevDir);\n }\n\n const browserslistData = browserslist(undefined, { path: this.basePath });\n\n this.renderWorker = new Piscina({\n filename: require.resolve('./stylesheet-processor-worker'),\n maxThreads,\n env: {\n ...process.env,\n FORCE_COLOR: '' + colors.enabled,\n },\n workerData: {\n tailwindConfigPath: await getTailwindConfigPath(this.projectBasePath),\n projectBasePath: this.projectBasePath,\n browserslistData,\n targets: transformSupportedBrowsersToTargets(browserslistData),\n cacheDirectory: this.cacheDirectory,\n cssUrl: this.cssUrl,\n styleIncludePaths: styleIncludePaths,\n },\n });\n }\n}\n\nfunction transformSupportedBrowsersToTargets(supportedBrowsers: string[]): string[] {\n const transformed: string[] = [];\n\n // https://esbuild.github.io/api/#target\n const esBuildSupportedBrowsers = new Set(['safari', 'firefox', 'edge', 'chrome', 'ios']);\n\n for (const browser of supportedBrowsers) {\n let [browserName, version] = browser.split(' ');\n\n // browserslist uses the name `ios_saf` for iOS Safari whereas esbuild uses `ios`\n if (browserName === 'ios_saf') {\n browserName = 'ios';\n }\n\n // browserslist uses ranges `15.2-15.3` versions but only the lowest is required\n // to perform minimum supported feature checks. esbuild also expects a single version.\n [version] = version.split('-');\n\n if (esBuildSupportedBrowsers.has(browserName)) {\n if (browserName === 'safari' && version === 'TP') {\n // esbuild only supports numeric versions so `TP` is converted to a high number (999) since\n // a Technology Preview (TP) of Safari is assumed to support all currently known features.\n version = '999';\n }\n\n transformed.push(browserName + version);\n }\n }\n\n return transformed.length ? transformed : undefined;\n}\n\nasync function getTailwindConfigPath(projectRoot: string): Promise<string | undefined> {\n // A configuration file can exist in the project or workspace root\n // The list of valid config files can be found:\n // https://github.com/tailwindlabs/tailwindcss/blob/8845d112fb62d79815b50b3bae80c317450b8b92/src/util/resolveConfigPath.js#L46-L52\n const tailwindConfigFiles = ['tailwind.config.js', 'tailwind.config.cjs'];\n for (const configFile of tailwindConfigFiles) {\n // Irrespective of the name project level configuration should always take precedence.\n const fullPath = join(projectRoot, configFile);\n if (await exists(fullPath)) {\n return fullPath;\n }\n }\n\n return undefined;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng-packagr",
3
- "version": "15.0.2",
3
+ "version": "15.1.0-next.0",
4
4
  "description": "Compile and package Angular libraries in Angular Package Format (APF)",
5
5
  "keywords": [
6
6
  "apf",
@@ -32,7 +32,7 @@
32
32
  "main": "./public_api.js",
33
33
  "typings": "./public_api.d.ts",
34
34
  "dependencies": {
35
- "@rollup/plugin-json": "^5.0.0",
35
+ "@rollup/plugin-json": "^6.0.0",
36
36
  "@rollup/plugin-node-resolve": "^15.0.0",
37
37
  "ajv": "^8.11.0",
38
38
  "ansi-colors": "^4.1.3",
@@ -50,6 +50,7 @@
50
50
  "jsonc-parser": "^3.2.0",
51
51
  "less": "^4.1.3",
52
52
  "ora": "^5.1.0",
53
+ "piscina": "^3.2.0",
53
54
  "postcss": "^8.4.16",
54
55
  "postcss-url": "^10.1.3",
55
56
  "rollup": "^3.0.0",
@@ -60,10 +61,10 @@
60
61
  "esbuild": "^0.16.0"
61
62
  },
62
63
  "peerDependencies": {
63
- "@angular/compiler-cli": "^15.0.0-next",
64
+ "@angular/compiler-cli": "^15.0.0 || ^15.1.0-next.0 || ^15.2.0-next.0",
64
65
  "tailwindcss": "^2.0.0 || ^3.0.0",
65
66
  "tslib": "^2.3.0",
66
- "typescript": "~4.8.2"
67
+ "typescript": ">=4.8.2 <5.0"
67
68
  },
68
69
  "peerDependenciesMeta": {
69
70
  "tailwindcss": {