ng-packagr 13.0.0-rc.2 → 13.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -74,7 +74,7 @@ Create one `package.json` per npm package, run _ng-packagr_ for each!
74
74
 
75
75
  ## Features
76
76
 
77
- * :gift: Implements [Angular Package Format](https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/preview)
77
+ * :gift: Implements [Angular Package Format](https://angular.io/guide/angular-package-format)
78
78
  * :checkered_flag: Bundles your library in FESM2020
79
79
  * :school_satchel: npm package can be consumed by [Angular CLI](https://github.com/angular/angular-cli), [Webpack](https://github.com/webpack/webpack), or [SystemJS](https://github.com/systemjs/systemjs)
80
80
  * :dancer: Creates type definitions (`.d.ts`)
@@ -100,7 +100,7 @@ Create one `package.json` per npm package, run _ng-packagr_ for each!
100
100
 
101
101
  ## Knowledge
102
102
 
103
- [Angular Package Format v12.0](https://docs.google.com/document/d/1CZC2rcpxffTDfRDs6p1cfbmKNLA6x5O-NtkJglDaBVs/preview), design document at Google Docs
103
+ [Angular Package Format documentation](https://angular.io/guide/angular-package-format)
104
104
 
105
105
  Packaging Angular Libraries - Jason Aden at Angular Mountain View Meetup ([Jan 2018, 45min talk](https://www.youtube.com/watch?v=QfvwQEJVOig&t=3612s))
106
106
 
@@ -113,12 +113,7 @@ const writePackageTransform = (options) => (0, transform_1.transformFromPromise)
113
113
  fesm2020: relativeUnixFromDestPath(destinationFiles.fesm2020),
114
114
  fesm2015: relativeUnixFromDestPath(destinationFiles.fesm2015),
115
115
  typings: relativeUnixFromDestPath(destinationFiles.declarations),
116
- exports: ngEntryPoint.isSecondaryEntryPoint
117
- ? undefined
118
- : {
119
- ...ngEntryPoint.packageJson.exports,
120
- ...generatePackageExports(ngEntryPoint, graph),
121
- },
116
+ exports: ngEntryPoint.isSecondaryEntryPoint ? undefined : generatePackageExports(ngEntryPoint, graph),
122
117
  // webpack v4+ specific flag to enable advanced optimizations and code splitting
123
118
  sideEffects: (_a = ngEntryPoint.packageJson.sideEffects) !== null && _a !== void 0 ? _a : false,
124
119
  }, !!options.watch, compilationMode, spinner);
@@ -246,34 +241,45 @@ function checkNonPeerDependencies(packageJson, property, allowed, spinner) {
246
241
  }
247
242
  }
248
243
  }
244
+ /**
245
+ * Generates the `package.json` package exports following APF v13.
246
+ * This is supposed to match with: https://github.com/angular/angular/blob/e0667efa6eada64d1fb8b143840689090fc82e52/packages/bazel/src/ng_package/packager.ts#L415.
247
+ */
249
248
  function generatePackageExports({ destinationPath, packageJson }, graph) {
250
- const verifyNonConflictingExport = (subpath) => {
251
- var _a;
252
- if (((_a = packageJson.exports) === null || _a === void 0 ? void 0 : _a[subpath]) !== undefined) {
253
- throw Error('Found a conflicting subpath export in the `package.json` file that would be overridden by the ' +
254
- `packager. Please unset the mapping for: "${subpath}".`);
249
+ var _a;
250
+ const exports = (_a = packageJson.exports) !== null && _a !== void 0 ? _a : {};
251
+ const insertMappingOrError = (subpath, mapping) => {
252
+ if (exports[subpath] === undefined) {
253
+ exports[subpath] = {};
254
+ }
255
+ const subpathExport = exports[subpath];
256
+ // Go through all conditions that should be inserted. If the condition is already
257
+ // manually set of the subpath export, we throw an error. In general, we allow for
258
+ // additional conditions to be set. These will always precede the generated ones.
259
+ for (const conditionName of Object.keys(mapping)) {
260
+ if (subpathExport[conditionName] !== undefined) {
261
+ throw Error(`Found a conflicting export condition for "${subpath}". The "${conditionName}" ` +
262
+ `condition would be overridden by ng-packagr. Please unset it.`);
263
+ }
264
+ // **Note**: The order of the conditions is preserved even though we are setting
265
+ // the conditions once at a time (the latest assignment will be at the end).
266
+ subpathExport[conditionName] = mapping[conditionName];
255
267
  }
256
- };
257
- verifyNonConflictingExport('./package.json');
258
- const exports = {
259
- './package.json': {
260
- default: './package.json',
261
- },
262
268
  };
263
269
  const relativeUnixFromDestPath = (filePath) => './' + (0, path_1.ensureUnixPath)(path.relative(destinationPath, filePath));
270
+ insertMappingOrError('./package.json', { default: './package.json' });
264
271
  const entryPoints = graph.filter(nodes_1.isEntryPoint);
265
272
  for (const entryPoint of entryPoints) {
266
273
  const { destinationFiles, isSecondaryEntryPoint } = entryPoint.data.entryPoint;
267
274
  const subpath = isSecondaryEntryPoint ? `./${destinationFiles.directory}` : '.';
268
- verifyNonConflictingExport(subpath);
269
- exports[subpath] = {
275
+ insertMappingOrError(subpath, {
270
276
  types: relativeUnixFromDestPath(destinationFiles.declarations),
271
277
  esm2020: relativeUnixFromDestPath(destinationFiles.esm2020),
272
278
  es2020: relativeUnixFromDestPath(destinationFiles.fesm2020),
273
279
  es2015: relativeUnixFromDestPath(destinationFiles.fesm2015),
274
280
  node: relativeUnixFromDestPath(destinationFiles.fesm2015),
275
281
  default: relativeUnixFromDestPath(destinationFiles.fesm2020),
276
- };
282
+ });
277
283
  }
278
284
  return exports;
279
285
  }
@@ -1 +1 @@
1
- {"version":3,"file":"write-package.transform.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/write-package.transform.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAsB;AACtB,2CAA6B;AAE7B,2CAAwC;AACxC,qDAA6D;AAC7D,6CAA2C;AAC3C,uCAAkE;AAClE,2CAA6C;AAC7C,qDAAuC;AACvC,2CAAkD;AAClD,oCAAiH;AAO1G,MAAM,qBAAqB,GAAG,CAAC,OAAyB,EAAE,EAAE,CACjE,IAAA,gCAAoB,EAAC,KAAK,EAAC,KAAK,EAAC,EAAE;;IACjC,MAAM,OAAO,GAAG,IAAA,aAAG,EAAC;QAClB,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;IACH,MAAM,UAAU,GAAmB,KAAK,CAAC,IAAI,CAAC,IAAA,8BAAsB,GAAE,CAAC,CAAC;IACxE,MAAM,YAAY,GAAiB,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;IAC9D,MAAM,aAA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C7C,MAAM,OAAO,GAAmB;QAC9B,gBAAgB,EAAE;YAChB,OAAO,EAAE,gBAAgB;SAC1B;KACF,CAAC;IAEF,MAAM,wBAAwB,GAAG,CAAC,QAAgB,EAAE,EAAE,CACpD,IAAI,GAAG,IAAA,qBAAc,EAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC,CAAC;IAElE,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,oBAAY,CAAC,CAAC;IAC/C,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,MAAM,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;QAC/E,MAAM,OAAO,GAAG,qBAAqB,CAAC,CAAC,CAAC,KAAK,gBAAgB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QAEhF,0BAA0B,CAAC,OAAO,CAAC,CAAC;QAEpC,OAAO,CAAC,OAAO,CAAC,GAAG;YACjB,KAAK,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,YAAY,CAAC;YAC9D,OAAO,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,OAAO,CAAC;YAC3D,MAAM,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,QAAQ,CAAC;YAC3D,MAAM,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,QAAQ,CAAC;YAC3D,IAAI,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,QAAQ,CAAC;YACzD,OAAO,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,QAAQ,CAAC;SAC7D,CAAC;KACH;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import ora from 'ora';\nimport * as path from 'path';\nimport { BuildGraph } from '../../graph/build-graph';\nimport { Node } from '../../graph/node';\nimport { transformFromPromise } from '../../graph/transform';\nimport { colors } from '../../utils/color';\nimport { copyFile, rmdir, stat, writeFile } from '../../utils/fs';\nimport { globFiles } from '../../utils/glob';\nimport * as log from '../../utils/log';\nimport { ensureUnixPath } from '../../utils/path';\nimport { EntryPointNode, PackageNode, fileUrl, isEntryPoint, isEntryPointInProgress, isPackage } from '../nodes';\nimport { NgPackagrOptions } from '../options.di';\nimport { NgPackage } from '../package';\nimport { NgEntryPoint } from './entry-point';\n\ntype CompilationMode = 'partial' | 'full' | undefined;\n\nexport const writePackageTransform = (options: NgPackagrOptions) =>\n transformFromPromise(async graph => {\n const spinner = ora({\n hideCursor: false,\n discardStdin: false,\n });\n const entryPoint: EntryPointNode = graph.find(isEntryPointInProgress());\n const ngEntryPoint: NgEntryPoint = entryPoint.data.entryPoint;\n const ngPackageNode: PackageNode = graph.find(isPackage);\n const ngPackage = ngPackageNode.data;\n const { destinationFiles } = entryPoint.data;\n const ignorePaths: string[] = [\n '.gitkeep',\n '**/.DS_Store',\n '**/Thumbs.db',\n '**/node_modules/**',\n `${ngPackage.dest}/**`,\n ];\n\n if (!ngEntryPoint.isSecondaryEntryPoint) {\n const assetFiles: string[] = [];\n\n // COPY ASSET FILES TO DESTINATION\n spinner.start('Copying assets');\n\n try {\n for (const asset of [...ngPackage.assets, 'LICENSE', '**/README.md']) {\n let assetFullPath = path.join(ngPackage.src, asset);\n\n try {\n const stats = await stat(assetFullPath);\n if (stats.isFile()) {\n assetFiles.push(assetFullPath);\n continue;\n }\n\n if (stats.isDirectory()) {\n assetFullPath = path.join(assetFullPath, '**/*');\n }\n } catch {}\n\n if (asset === 'LICENSE') {\n continue;\n }\n\n const files = await globFiles(assetFullPath, {\n ignore: ignorePaths,\n cache: ngPackageNode.cache.globCache,\n dot: true,\n nodir: true,\n });\n\n if (files.length) {\n assetFiles.push(...files);\n }\n }\n\n for (const file of assetFiles) {\n const relativePath = path.relative(ngPackage.src, file);\n const destination = path.resolve(ngPackage.dest, relativePath);\n const nodeUri = fileUrl(ensureUnixPath(file));\n let node = graph.get(nodeUri);\n if (!node) {\n node = new Node(nodeUri);\n graph.put(node);\n }\n\n entryPoint.dependsOn(node);\n await copyFile(file, destination);\n }\n } catch (error) {\n spinner.fail();\n throw error;\n }\n spinner.succeed();\n }\n\n // 6. WRITE PACKAGE.JSON\n try {\n spinner.start('Writing package manifest');\n const relativeUnixFromDestPath = (filePath: string) =>\n ensureUnixPath(path.relative(ngEntryPoint.destinationPath, filePath));\n\n const { compilationMode } = entryPoint.data.tsConfig.options;\n\n await writePackageJson(\n ngEntryPoint,\n ngPackage,\n {\n module: relativeUnixFromDestPath(destinationFiles.fesm2015),\n es2020: relativeUnixFromDestPath(destinationFiles.fesm2020),\n esm2020: relativeUnixFromDestPath(destinationFiles.esm2020),\n fesm2020: relativeUnixFromDestPath(destinationFiles.fesm2020),\n fesm2015: relativeUnixFromDestPath(destinationFiles.fesm2015),\n typings: relativeUnixFromDestPath(destinationFiles.declarations),\n exports: ngEntryPoint.isSecondaryEntryPoint\n ? undefined\n : {\n ...ngEntryPoint.packageJson.exports,\n ...generatePackageExports(ngEntryPoint, graph),\n },\n // webpack v4+ specific flag to enable advanced optimizations and code splitting\n sideEffects: ngEntryPoint.packageJson.sideEffects ?? false,\n },\n !!options.watch,\n compilationMode as CompilationMode,\n spinner,\n );\n } catch (error) {\n spinner.fail();\n throw error;\n }\n spinner.succeed();\n spinner.succeed(`Built ${ngEntryPoint.moduleId}`);\n\n return graph;\n });\n\n/**\n * Creates and writes a `package.json` file of the entry point used by the `node_module`\n * resolution strategies.\n *\n * #### Example\n *\n * A consumer of the entry point depends on it by `import {..} from '@my/module/id';`.\n * The module id `@my/module/id` will be resolved to the `package.json` file that is written by\n * this build step.\n * The properties `main`, `module`, `typings` (and so on) in the `package.json` point to the\n * flattened JavaScript bundles, type definitions, (...).\n *\n * @param entryPoint An entry point of an Angular package / library\n * @param additionalProperties Additional properties, e.g. binary artefacts (bundle files), to merge into `package.json`\n */\nasync function writePackageJson(\n entryPoint: NgEntryPoint,\n pkg: NgPackage,\n additionalProperties: { [key: string]: string | boolean | string[] },\n isWatchMode: boolean,\n compilationMode: CompilationMode,\n spinner: ora.Ora,\n): Promise<void> {\n log.debug('Writing package.json');\n\n // set additional properties\n const packageJson = { ...entryPoint.packageJson, ...additionalProperties };\n\n // read tslib version from `@angular/compiler` so that our tslib\n // version at least matches that of angular if we use require('tslib').version\n // it will get what installed and not the minimum version nor if it is a `~` or `^`\n // this is only required for primary\n if (!entryPoint.isSecondaryEntryPoint) {\n if (isWatchMode) {\n // Needed because of Webpack's 5 `cachemanagedpaths`\n // https://github.com/angular/angular-cli/issues/20962\n packageJson.version = `0.0.0-watch+${Date.now()}`;\n }\n\n if (!packageJson.peerDependencies?.tslib && !packageJson.dependencies?.tslib) {\n const {\n peerDependencies: angularPeerDependencies = {},\n dependencies: angularDependencies = {},\n } = require('@angular/compiler/package.json');\n const tsLibVersion = angularPeerDependencies.tslib || angularDependencies.tslib;\n\n if (tsLibVersion) {\n packageJson.dependencies = {\n ...packageJson.dependencies,\n tslib: tsLibVersion,\n };\n }\n } else if (packageJson.peerDependencies?.tslib) {\n spinner.warn(\n colors.yellow(\n `'tslib' is no longer recommended to be used as a 'peerDependencies'. Moving it to 'dependencies'.`,\n ),\n );\n packageJson.dependencies = {\n ...(packageJson.dependencies || {}),\n tslib: packageJson.peerDependencies.tslib,\n };\n\n delete packageJson.peerDependencies.tslib;\n }\n }\n\n // Verify non-peerDependencies as they can easily lead to duplicate installs or version conflicts\n // in the node_modules folder of an application\n const allowedList = pkg.allowedNonPeerDependencies.map(value => new RegExp(value));\n try {\n checkNonPeerDependencies(packageJson, 'dependencies', allowedList, spinner);\n } catch (e) {\n await rmdir(entryPoint.destinationPath, { recursive: true });\n throw e;\n }\n\n // Removes scripts from package.json after build\n if (packageJson.scripts) {\n if (pkg.keepLifecycleScripts !== true) {\n spinner.info(`Removing scripts section in package.json as it's considered a potential security vulnerability.`);\n delete packageJson.scripts;\n } else {\n spinner.warn(\n colors.yellow(\n `You enabled keepLifecycleScripts explicitly. The scripts section in package.json will be published to npm.`,\n ),\n );\n }\n }\n\n if (!entryPoint.isSecondaryEntryPoint && compilationMode !== 'partial') {\n const scripts = packageJson.scripts || (packageJson.scripts = {});\n scripts.prepublishOnly =\n 'node --eval \"console.error(\\'' +\n 'ERROR: Trying to publish a package that has been compiled by Ivy in full compilation mode. This is not allowed.\\\\n' +\n 'Please delete and rebuild the package with Ivy partial compilation mode, before attempting to publish.\\\\n' +\n '\\')\" ' +\n '&& exit 1';\n }\n\n // keep the dist package.json clean\n // this will not throw if ngPackage field does not exist\n delete packageJson.ngPackage;\n\n const packageJsonPropertiesToDelete = [\n 'stylelint',\n 'prettier',\n 'browserslist',\n 'devDependencies',\n 'jest',\n 'workspaces',\n 'husky',\n ];\n\n for (const prop of packageJsonPropertiesToDelete) {\n if (prop in packageJson) {\n delete packageJson[prop];\n spinner.info(`Removing ${prop} section in package.json.`);\n }\n }\n\n packageJson.name = entryPoint.moduleId;\n await writeFile(path.join(entryPoint.destinationPath, 'package.json'), JSON.stringify(packageJson, undefined, 2));\n}\n\nfunction checkNonPeerDependencies(\n packageJson: Record<string, unknown>,\n property: string,\n allowed: RegExp[],\n spinner: ora.Ora,\n) {\n if (!packageJson[property]) {\n return;\n }\n\n for (const dep of Object.keys(packageJson[property])) {\n if (allowed.some(regex => regex.test(dep))) {\n log.debug(`Dependency ${dep} is allowed in '${property}'`);\n } else {\n spinner.warn(\n colors.yellow(\n `Distributing npm packages with '${property}' is not recommended. Please consider adding ${dep}` +\n `to 'peerDependencies' or remove it from '${property}'.`,\n ),\n );\n throw new Error(`Dependency ${dep} must be explicitly allowed using the \"allowedNonPeerDependencies\" option.`);\n }\n }\n}\n\ntype PackageExports = Record<string, Record<string, string>>;\nfunction generatePackageExports(\n { destinationPath, packageJson }: NgEntryPoint,\n graph: BuildGraph,\n): PackageExports | undefined {\n const verifyNonConflictingExport = (subpath: string) => {\n if (packageJson.exports?.[subpath] !== undefined) {\n throw Error(\n 'Found a conflicting subpath export in the `package.json` file that would be overridden by the ' +\n `packager. Please unset the mapping for: \"${subpath}\".`,\n );\n }\n };\n\n verifyNonConflictingExport('./package.json');\n const exports: PackageExports = {\n './package.json': {\n default: './package.json',\n },\n };\n\n const relativeUnixFromDestPath = (filePath: string) =>\n './' + ensureUnixPath(path.relative(destinationPath, filePath));\n\n const entryPoints = graph.filter(isEntryPoint);\n for (const entryPoint of entryPoints) {\n const { destinationFiles, isSecondaryEntryPoint } = entryPoint.data.entryPoint;\n const subpath = isSecondaryEntryPoint ? `./${destinationFiles.directory}` : '.';\n\n verifyNonConflictingExport(subpath);\n\n exports[subpath] = {\n types: relativeUnixFromDestPath(destinationFiles.declarations),\n esm2020: relativeUnixFromDestPath(destinationFiles.esm2020),\n es2020: relativeUnixFromDestPath(destinationFiles.fesm2020),\n es2015: relativeUnixFromDestPath(destinationFiles.fesm2015),\n node: relativeUnixFromDestPath(destinationFiles.fesm2015),\n default: relativeUnixFromDestPath(destinationFiles.fesm2020),\n };\n }\n\n return exports;\n}\n"]}
1
+ {"version":3,"file":"write-package.transform.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/write-package.transform.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAsB;AACtB,2CAA6B;AAE7B,2CAAwC;AACxC,qDAA6D;AAC7D,6CAA2C;AAC3C,uCAAkE;AAClE,2CAA6C;AAC7C,qDAAuC;AACvC,2CAAkD;AAClD,oCAAiH;AAO1G,MAAM,qBAAqB,GAAG,CAAC,OAAyB,EAAE,EAAE,CACjE,IAAA,gCAAoB,EAAC,KAAK,EAAC,KAAK,EAAC,EAAE;;IACjC,MAAM,OAAO,GAAG,IAAA,aAAG,EAAC;QAClB,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;IACH,MAAM,UAAU,GAAmB,KAAK,CAAC,IAAI,CAAC,IAAA,8BAAsB,GAAE,CAAC,CAAC;IACxE,MAAM,YAAY,GAAiB,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;IAC9D,MAAM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AC,QAAQ,CAAC;YACzD,OAAO,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,QAAQ,CAAC;SAC7D,CAAC,CAAC;KACJ;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import ora from 'ora';\nimport * as path from 'path';\nimport { BuildGraph } from '../../graph/build-graph';\nimport { Node } from '../../graph/node';\nimport { transformFromPromise } from '../../graph/transform';\nimport { colors } from '../../utils/color';\nimport { copyFile, rmdir, stat, writeFile } from '../../utils/fs';\nimport { globFiles } from '../../utils/glob';\nimport * as log from '../../utils/log';\nimport { ensureUnixPath } from '../../utils/path';\nimport { EntryPointNode, PackageNode, fileUrl, isEntryPoint, isEntryPointInProgress, isPackage } from '../nodes';\nimport { NgPackagrOptions } from '../options.di';\nimport { NgPackage } from '../package';\nimport { NgEntryPoint } from './entry-point';\n\ntype CompilationMode = 'partial' | 'full' | undefined;\n\nexport const writePackageTransform = (options: NgPackagrOptions) =>\n transformFromPromise(async graph => {\n const spinner = ora({\n hideCursor: false,\n discardStdin: false,\n });\n const entryPoint: EntryPointNode = graph.find(isEntryPointInProgress());\n const ngEntryPoint: NgEntryPoint = entryPoint.data.entryPoint;\n const ngPackageNode: PackageNode = graph.find(isPackage);\n const ngPackage = ngPackageNode.data;\n const { destinationFiles } = entryPoint.data;\n const ignorePaths: string[] = [\n '.gitkeep',\n '**/.DS_Store',\n '**/Thumbs.db',\n '**/node_modules/**',\n `${ngPackage.dest}/**`,\n ];\n\n if (!ngEntryPoint.isSecondaryEntryPoint) {\n const assetFiles: string[] = [];\n\n // COPY ASSET FILES TO DESTINATION\n spinner.start('Copying assets');\n\n try {\n for (const asset of [...ngPackage.assets, 'LICENSE', '**/README.md']) {\n let assetFullPath = path.join(ngPackage.src, asset);\n\n try {\n const stats = await stat(assetFullPath);\n if (stats.isFile()) {\n assetFiles.push(assetFullPath);\n continue;\n }\n\n if (stats.isDirectory()) {\n assetFullPath = path.join(assetFullPath, '**/*');\n }\n } catch {}\n\n if (asset === 'LICENSE') {\n continue;\n }\n\n const files = await globFiles(assetFullPath, {\n ignore: ignorePaths,\n cache: ngPackageNode.cache.globCache,\n dot: true,\n nodir: true,\n });\n\n if (files.length) {\n assetFiles.push(...files);\n }\n }\n\n for (const file of assetFiles) {\n const relativePath = path.relative(ngPackage.src, file);\n const destination = path.resolve(ngPackage.dest, relativePath);\n const nodeUri = fileUrl(ensureUnixPath(file));\n let node = graph.get(nodeUri);\n if (!node) {\n node = new Node(nodeUri);\n graph.put(node);\n }\n\n entryPoint.dependsOn(node);\n await copyFile(file, destination);\n }\n } catch (error) {\n spinner.fail();\n throw error;\n }\n spinner.succeed();\n }\n\n // 6. WRITE PACKAGE.JSON\n try {\n spinner.start('Writing package manifest');\n const relativeUnixFromDestPath = (filePath: string) =>\n ensureUnixPath(path.relative(ngEntryPoint.destinationPath, filePath));\n\n const { compilationMode } = entryPoint.data.tsConfig.options;\n\n await writePackageJson(\n ngEntryPoint,\n ngPackage,\n {\n module: relativeUnixFromDestPath(destinationFiles.fesm2015),\n es2020: relativeUnixFromDestPath(destinationFiles.fesm2020),\n esm2020: relativeUnixFromDestPath(destinationFiles.esm2020),\n fesm2020: relativeUnixFromDestPath(destinationFiles.fesm2020),\n fesm2015: relativeUnixFromDestPath(destinationFiles.fesm2015),\n typings: relativeUnixFromDestPath(destinationFiles.declarations),\n exports: ngEntryPoint.isSecondaryEntryPoint ? undefined : generatePackageExports(ngEntryPoint, graph),\n // webpack v4+ specific flag to enable advanced optimizations and code splitting\n sideEffects: ngEntryPoint.packageJson.sideEffects ?? false,\n },\n !!options.watch,\n compilationMode as CompilationMode,\n spinner,\n );\n } catch (error) {\n spinner.fail();\n throw error;\n }\n spinner.succeed();\n spinner.succeed(`Built ${ngEntryPoint.moduleId}`);\n\n return graph;\n });\n\n/**\n * Creates and writes a `package.json` file of the entry point used by the `node_module`\n * resolution strategies.\n *\n * #### Example\n *\n * A consumer of the entry point depends on it by `import {..} from '@my/module/id';`.\n * The module id `@my/module/id` will be resolved to the `package.json` file that is written by\n * this build step.\n * The properties `main`, `module`, `typings` (and so on) in the `package.json` point to the\n * flattened JavaScript bundles, type definitions, (...).\n *\n * @param entryPoint An entry point of an Angular package / library\n * @param additionalProperties Additional properties, e.g. binary artefacts (bundle files), to merge into `package.json`\n */\nasync function writePackageJson(\n entryPoint: NgEntryPoint,\n pkg: NgPackage,\n additionalProperties: { [key: string]: string | boolean | string[] | ConditionalExport },\n isWatchMode: boolean,\n compilationMode: CompilationMode,\n spinner: ora.Ora,\n): Promise<void> {\n log.debug('Writing package.json');\n\n // set additional properties\n const packageJson = { ...entryPoint.packageJson, ...additionalProperties };\n\n // read tslib version from `@angular/compiler` so that our tslib\n // version at least matches that of angular if we use require('tslib').version\n // it will get what installed and not the minimum version nor if it is a `~` or `^`\n // this is only required for primary\n if (!entryPoint.isSecondaryEntryPoint) {\n if (isWatchMode) {\n // Needed because of Webpack's 5 `cachemanagedpaths`\n // https://github.com/angular/angular-cli/issues/20962\n packageJson.version = `0.0.0-watch+${Date.now()}`;\n }\n\n if (!packageJson.peerDependencies?.tslib && !packageJson.dependencies?.tslib) {\n const {\n peerDependencies: angularPeerDependencies = {},\n dependencies: angularDependencies = {},\n } = require('@angular/compiler/package.json');\n const tsLibVersion = angularPeerDependencies.tslib || angularDependencies.tslib;\n\n if (tsLibVersion) {\n packageJson.dependencies = {\n ...packageJson.dependencies,\n tslib: tsLibVersion,\n };\n }\n } else if (packageJson.peerDependencies?.tslib) {\n spinner.warn(\n colors.yellow(\n `'tslib' is no longer recommended to be used as a 'peerDependencies'. Moving it to 'dependencies'.`,\n ),\n );\n packageJson.dependencies = {\n ...(packageJson.dependencies || {}),\n tslib: packageJson.peerDependencies.tslib,\n };\n\n delete packageJson.peerDependencies.tslib;\n }\n }\n\n // Verify non-peerDependencies as they can easily lead to duplicate installs or version conflicts\n // in the node_modules folder of an application\n const allowedList = pkg.allowedNonPeerDependencies.map(value => new RegExp(value));\n try {\n checkNonPeerDependencies(packageJson, 'dependencies', allowedList, spinner);\n } catch (e) {\n await rmdir(entryPoint.destinationPath, { recursive: true });\n throw e;\n }\n\n // Removes scripts from package.json after build\n if (packageJson.scripts) {\n if (pkg.keepLifecycleScripts !== true) {\n spinner.info(`Removing scripts section in package.json as it's considered a potential security vulnerability.`);\n delete packageJson.scripts;\n } else {\n spinner.warn(\n colors.yellow(\n `You enabled keepLifecycleScripts explicitly. The scripts section in package.json will be published to npm.`,\n ),\n );\n }\n }\n\n if (!entryPoint.isSecondaryEntryPoint && compilationMode !== 'partial') {\n const scripts = packageJson.scripts || (packageJson.scripts = {});\n scripts.prepublishOnly =\n 'node --eval \"console.error(\\'' +\n 'ERROR: Trying to publish a package that has been compiled by Ivy in full compilation mode. This is not allowed.\\\\n' +\n 'Please delete and rebuild the package with Ivy partial compilation mode, before attempting to publish.\\\\n' +\n '\\')\" ' +\n '&& exit 1';\n }\n\n // keep the dist package.json clean\n // this will not throw if ngPackage field does not exist\n delete packageJson.ngPackage;\n\n const packageJsonPropertiesToDelete = [\n 'stylelint',\n 'prettier',\n 'browserslist',\n 'devDependencies',\n 'jest',\n 'workspaces',\n 'husky',\n ];\n\n for (const prop of packageJsonPropertiesToDelete) {\n if (prop in packageJson) {\n delete packageJson[prop];\n spinner.info(`Removing ${prop} section in package.json.`);\n }\n }\n\n packageJson.name = entryPoint.moduleId;\n await writeFile(path.join(entryPoint.destinationPath, 'package.json'), JSON.stringify(packageJson, undefined, 2));\n}\n\nfunction checkNonPeerDependencies(\n packageJson: Record<string, unknown>,\n property: string,\n allowed: RegExp[],\n spinner: ora.Ora,\n) {\n if (!packageJson[property]) {\n return;\n }\n\n for (const dep of Object.keys(packageJson[property])) {\n if (allowed.some(regex => regex.test(dep))) {\n log.debug(`Dependency ${dep} is allowed in '${property}'`);\n } else {\n spinner.warn(\n colors.yellow(\n `Distributing npm packages with '${property}' is not recommended. Please consider adding ${dep}` +\n `to 'peerDependencies' or remove it from '${property}'.`,\n ),\n );\n throw new Error(`Dependency ${dep} must be explicitly allowed using the \"allowedNonPeerDependencies\" option.`);\n }\n }\n}\n\ntype PackageExports = Record<string, ConditionalExport>;\n\n/**\n * Type describing the conditional exports descriptor for an entry-point.\n * https://nodejs.org/api/packages.html#packages_conditional_exports\n */\ntype ConditionalExport = {\n node?: string;\n types?: string;\n esm2020?: string;\n es2020?: string;\n es2015?: string;\n default?: string;\n};\n\n/**\n * Generates the `package.json` package exports following APF v13.\n * This is supposed to match with: https://github.com/angular/angular/blob/e0667efa6eada64d1fb8b143840689090fc82e52/packages/bazel/src/ng_package/packager.ts#L415.\n */\nfunction generatePackageExports({ destinationPath, packageJson }: NgEntryPoint, graph: BuildGraph): PackageExports {\n const exports: PackageExports = packageJson.exports ?? {};\n\n const insertMappingOrError = (subpath: string, mapping: ConditionalExport) => {\n if (exports[subpath] === undefined) {\n exports[subpath] = {};\n }\n\n const subpathExport = exports[subpath];\n\n // Go through all conditions that should be inserted. If the condition is already\n // manually set of the subpath export, we throw an error. In general, we allow for\n // additional conditions to be set. These will always precede the generated ones.\n for (const conditionName of Object.keys(mapping) as [keyof ConditionalExport]) {\n if (subpathExport[conditionName] !== undefined) {\n throw Error(\n `Found a conflicting export condition for \"${subpath}\". The \"${conditionName}\" ` +\n `condition would be overridden by ng-packagr. Please unset it.`,\n );\n }\n\n // **Note**: The order of the conditions is preserved even though we are setting\n // the conditions once at a time (the latest assignment will be at the end).\n subpathExport[conditionName] = mapping[conditionName];\n }\n };\n\n const relativeUnixFromDestPath = (filePath: string) =>\n './' + ensureUnixPath(path.relative(destinationPath, filePath));\n\n insertMappingOrError('./package.json', { default: './package.json' });\n\n const entryPoints = graph.filter(isEntryPoint);\n for (const entryPoint of entryPoints) {\n const { destinationFiles, isSecondaryEntryPoint } = entryPoint.data.entryPoint;\n const subpath = isSecondaryEntryPoint ? `./${destinationFiles.directory}` : '.';\n\n insertMappingOrError(subpath, {\n types: relativeUnixFromDestPath(destinationFiles.declarations),\n esm2020: relativeUnixFromDestPath(destinationFiles.esm2020),\n es2020: relativeUnixFromDestPath(destinationFiles.fesm2020),\n es2015: relativeUnixFromDestPath(destinationFiles.fesm2015),\n node: relativeUnixFromDestPath(destinationFiles.fesm2015),\n default: relativeUnixFromDestPath(destinationFiles.fesm2020),\n });\n }\n\n return exports;\n}\n"]}
@@ -16,13 +16,14 @@ export interface Result {
16
16
  export declare class StylesheetProcessor {
17
17
  private readonly basePath;
18
18
  private readonly cssUrl?;
19
- private readonly styleIncludePaths?;
19
+ private readonly includePaths?;
20
20
  private readonly cacheDirectory?;
21
21
  private browserslistData;
22
22
  private targets;
23
23
  private postCssProcessor;
24
24
  private esbuild;
25
- constructor(basePath: string, cssUrl?: CssUrl, styleIncludePaths?: string[], cacheDirectory?: string | false);
25
+ private styleIncludePaths;
26
+ constructor(basePath: string, cssUrl?: CssUrl, includePaths?: string[], cacheDirectory?: string | false);
26
27
  process({ filePath, content }: {
27
28
  filePath: string;
28
29
  content: string;
@@ -46,10 +46,10 @@ var InlineStyleLanguage;
46
46
  InlineStyleLanguage["less"] = "less";
47
47
  })(InlineStyleLanguage = exports.InlineStyleLanguage || (exports.InlineStyleLanguage = {}));
48
48
  class StylesheetProcessor {
49
- constructor(basePath, cssUrl, styleIncludePaths, cacheDirectory) {
49
+ constructor(basePath, cssUrl, includePaths, cacheDirectory) {
50
50
  this.basePath = basePath;
51
51
  this.cssUrl = cssUrl;
52
- this.styleIncludePaths = styleIncludePaths;
52
+ this.includePaths = includePaths;
53
53
  this.cacheDirectory = cacheDirectory;
54
54
  this.esbuild = new esbuild_executor_1.EsbuildExecutor();
55
55
  log.debug(`determine browserslist for ${this.basePath}`);
@@ -65,6 +65,8 @@ class StylesheetProcessor {
65
65
  'last 2 iOS major versions',
66
66
  'Firefox ESR',
67
67
  ];
68
+ const rootNodeModules = (0, find_parent_dir_1.sync)(basePath, 'node_modules');
69
+ this.styleIncludePaths = [...this.includePaths, (0, path_1.join)(rootNodeModules, 'node_modules')];
68
70
  this.browserslistData = (0, browserslist_1.default)(undefined, { path: this.basePath });
69
71
  this.targets = transformSupportedBrowsersToTargets(this.browserslistData);
70
72
  this.postCssProcessor = this.createPostCssPlugins();
@@ -1 +1 @@
1
- {"version":3,"file":"stylesheet-processor.js","sourceRoot":"","sources":["../../../src/lib/styles/stylesheet-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAAwC;AACxC,qDAAuC;AACvC,2BAAgC;AAChC,+BAAiD;AACjD,sDAA8B;AAC9B,4EAAkD;AAClD,8DAAqC;AACrC,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;AAED,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC7B,oCAAa,CAAA;IACb,oCAAa,CAAA;IACb,kCAAW,CAAA;IACX,oCAAa,CAAA;AACf,CAAC,EALW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAK9B;AAOD,MAAa,mBAAmB;IAM9B,YACmB,QAAgB,EAChB,MAAe,EACf,iBAA4B,EAC5B,cAA+B;QAH/B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAS;QACf,sBAAiB,GAAjB,iBAAiB,CAAW;QAC5B,mBAAc,GAAd,cAAc,CAAiB;QAN1C,YAAO,GAAG,IAAI,kCAAe,EAAE,CAAC;QAQtC,GAAG,CAAC,KAAK,CAAC,8BAA8B,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzD,sDAAsD;QACtD,gHAAgH;QAEhH,gEAAgE;QAChE,2CAA2C;QAC1C,sBAAY,CAAC,QAAqB,GAAG;YACpC,uBAAuB;YACvB,wBAAwB;YACxB,4BAA4B;YAC5B,8BAA8B;YAC9B,2BAA2B;YAC3B,aAAa;SACd,CAAC;QAEF,IAAI,CAAC,gBAAgB,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,cAAO,EAAC,QAAQ,CAAC,CAAC,EAAE;QACzD,OAAO,QAAQ,CAAC;KACjB;IAED,OAAO,aAAa,CAAC,MAAM,EAAE,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["import browserslist from 'browserslist';\nimport { sync } from 'find-parent-dir';\nimport { existsSync } from 'fs';\nimport { dirname, extname, resolve } from 'path';\nimport postcss from 'postcss';\nimport postcssPresetEnv from 'postcss-preset-env';\nimport postcssUrl from 'postcss-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 enum InlineStyleLanguage {\n sass = 'sass',\n scss = 'scss',\n css = 'css',\n less = 'less',\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\n constructor(\n private readonly basePath: string,\n private readonly cssUrl?: CssUrl,\n private readonly styleIncludePaths?: string[],\n private readonly 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.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 if (this.cssUrl !== CssUrl.none) {\n postCssPlugins.push(postcssUrl({ url: this.cssUrl }));\n }\n\n postCssPlugins.push(\n postcssPresetEnv({\n browsers: this.browserslistData,\n autoprefixer: true,\n stage: 3,\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'))\n .renderSync({\n file: filePath,\n data: css,\n indentedSyntax: '.sass' === ext,\n importer: customSassImporter,\n includePaths: this.styleIncludePaths,\n })\n .css.toString();\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 case '.styl':\n case '.stylus': {\n const stylus = (await import('stylus')).default;\n\n return (\n stylus(css)\n // add paths for resolve\n .set('paths', [this.basePath, '.', ...this.styleIncludePaths, 'node_modules'])\n // add support for resolving plugins from node_modules\n .set('filename', filePath)\n // turn on url resolver in stylus, same as flag --resolve-url\n .set('resolve url', true)\n .define('url', stylus.resolver(undefined))\n .render()\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 // browserslist also uses ranges for iOS Safari 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\n if (browserName === 'ie') {\n transformed.push('edge12');\n } else 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 customSassImporter(url: string, prev: string): { file: string; prev: string } | undefined {\n // NB: Sass importer should always be sync as otherwise it will cause\n // sass to go in the async path which is slower.\n if (url[0] !== '~') {\n return undefined;\n }\n\n const result = resolveImport(url.substr(1), prev);\n if (!result) {\n return undefined;\n }\n\n return {\n file: result,\n prev,\n };\n}\n\nfunction resolveImport(target: string, basePath: string): string | undefined {\n const root = sync(basePath, 'node_modules');\n if (!root) {\n return undefined;\n }\n\n const filePath = resolve(root, 'node_modules', target);\n if (existsSync(filePath) || existsSync(dirname(filePath))) {\n return filePath;\n }\n\n return resolveImport(target, dirname(root));\n}\n"]}
1
+ {"version":3,"file":"stylesheet-processor.js","sourceRoot":"","sources":["../../../src/lib/styles/stylesheet-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAAwC;AACxC,qDAAuC;AACvC,2BAAgC;AAChC,+BAAuD;AACvD,sDAA8B;AAC9B,4EAAkD;AAClD,8DAAqC;AACrC,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;AAED,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC7B,oCAAa,CAAA;IACb,oCAAa,CAAA;IACb,kCAAW,CAAA;IACX,oCAAa,CAAA;AACf,CAAC,EALW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAK9B;AAOD,MAAa,mBAAmB;IAO9B,YACmB,QAAgB,EAChB,MAAe,EACf,YAAuB,EACvB,cAA+B;QAH/B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAS;QACf,iBAAY,GAAZ,YAAY,CAAW;QACvB,mBAAc,GAAd,cAAc,CAAiB;QAP1C,YAAO,GAAG,IAAI,kCAAe,EAAE,CAAC;QAStC,GAAG,CAAC,KAAK,CAAC,8BAA8B,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACzD,sDAAsD;QACtD,gHAAgH;QAEhH,gEAAgE;QAChE,2CAA2C;QAC1C,sBAAY,CAAC,QAAqB,GAAG;YACpC,uBAAuB;YACvB,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AAE,QAAgB;IACrD,MAAM,IAAI,GAAG,IAAA,sBAAI,EAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IAC5C,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,QAAQ,GAAG,IAAA,cAAO,EAAC,IAAI,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IACvD,IAAI,IAAA,eAAU,EAAC,QAAQ,CAAC,IAAI,IAAA,eAAU,EAAC,IAAA,cAAO,EAAC,QAAQ,CAAC,CAAC,EAAE;QACzD,OAAO,QAAQ,CAAC;KACjB;IAED,OAAO,aAAa,CAAC,MAAM,EAAE,IAAA,cAAO,EAAC,IAAI,CAAC,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["import browserslist from 'browserslist';\nimport { sync } from 'find-parent-dir';\nimport { existsSync } from 'fs';\nimport { dirname, extname, join, resolve } from 'path';\nimport postcss from 'postcss';\nimport postcssPresetEnv from 'postcss-preset-env';\nimport postcssUrl from 'postcss-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 enum InlineStyleLanguage {\n sass = 'sass',\n scss = 'scss',\n css = 'css',\n less = 'less',\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\n constructor(\n private readonly basePath: string,\n private readonly cssUrl?: CssUrl,\n private readonly includePaths?: string[],\n private readonly 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 const rootNodeModules = sync(basePath, 'node_modules');\n this.styleIncludePaths = [...this.includePaths, join(rootNodeModules, 'node_modules')];\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 if (this.cssUrl !== CssUrl.none) {\n postCssPlugins.push(postcssUrl({ url: this.cssUrl }));\n }\n\n postCssPlugins.push(\n postcssPresetEnv({\n browsers: this.browserslistData,\n autoprefixer: true,\n stage: 3,\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'))\n .renderSync({\n file: filePath,\n data: css,\n indentedSyntax: '.sass' === ext,\n importer: customSassImporter,\n includePaths: this.styleIncludePaths,\n })\n .css.toString();\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 case '.styl':\n case '.stylus': {\n const stylus = (await import('stylus')).default;\n\n return (\n stylus(css)\n // add paths for resolve\n .set('paths', [this.basePath, '.', ...this.styleIncludePaths, 'node_modules'])\n // add support for resolving plugins from node_modules\n .set('filename', filePath)\n // turn on url resolver in stylus, same as flag --resolve-url\n .set('resolve url', true)\n .define('url', stylus.resolver(undefined))\n .render()\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 // browserslist also uses ranges for iOS Safari 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\n if (browserName === 'ie') {\n transformed.push('edge12');\n } else 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 customSassImporter(url: string, prev: string): { file: string; prev: string } | undefined {\n // NB: Sass importer should always be sync as otherwise it will cause\n // sass to go in the async path which is slower.\n if (url[0] !== '~') {\n return undefined;\n }\n\n const result = resolveImport(url.substr(1), prev);\n if (!result) {\n return undefined;\n }\n\n return {\n file: result,\n prev,\n };\n}\n\nfunction resolveImport(target: string, basePath: string): string | undefined {\n const root = sync(basePath, 'node_modules');\n if (!root) {\n return undefined;\n }\n\n const filePath = resolve(root, 'node_modules', target);\n if (existsSync(filePath) || existsSync(dirname(filePath))) {\n return filePath;\n }\n\n return resolveImport(target, dirname(root));\n}\n"]}
@@ -77,7 +77,7 @@ async function initializeTsConfig(defaultTsConfig, entryPoints) {
77
77
  const defaultTsConfigParsed = await createDefaultTsConfig(defaultTsConfig);
78
78
  if (defaultTsConfigParsed.errors.length > 0) {
79
79
  const { formatDiagnostics } = await (0, ng_compiler_cli_1.ngCompilerCli)();
80
- throw formatDiagnostics(defaultTsConfigParsed.errors);
80
+ throw new Error(formatDiagnostics(defaultTsConfigParsed.errors));
81
81
  }
82
82
  if (defaultTsConfigParsed.options.enableIvy === false) {
83
83
  (0, log_1.warn)('Project is attempting to disable the Ivy compiler. ' +
@@ -1 +1 @@
1
- {"version":3,"file":"tsconfig.js","sourceRoot":"","sources":["../../../src/lib/ts/tsconfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,4DAA4B;AAE5B,kDAAoC;AACpC,sCAAoC;AACpC,8DAAyD;AAE5C,QAAA,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS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AK;IAErB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;IAE5D,sCAAsC;IACtC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE;QAC3B,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC;KAC7B;IAED,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE;QAC7B,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;QAChC,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,GAAG,UAAU,CAAC;QACjE,MAAM,UAAU,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;QAEnF,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;YACrC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;SAC/C;aAAM;YACL,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,CAAC;SACzD;KACF;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAzBD,oEAyBC","sourcesContent":["import type { CompilerOptions, ParsedConfiguration } from '@angular/compiler-cli';\nimport * as path from 'path';\nimport ts from 'typescript';\nimport { EntryPointNode } from '../ng-package/nodes';\nimport * as log from '../utils/log';\nimport { warn } from '../utils/log';\nimport { ngCompilerCli } from '../utils/ng-compiler-cli';\n\nexport const defaultTsConfigPath = path.join(__dirname, 'conf', 'tsconfig.ngc.json');\n/**\n * Reads the default TypeScript configuration.\n */\nasync function readDefaultTsConfig(fileName = defaultTsConfigPath): Promise<ParsedConfiguration> {\n // these options are mandatory\n const extraOptions: CompilerOptions = {\n moduleResolution: ts.ModuleResolutionKind.NodeJs,\n target: ts.ScriptTarget.ES2020,\n experimentalDecorators: true,\n\n // sourcemaps\n sourceMap: false,\n inlineSources: true,\n inlineSourceMap: true,\n\n outDir: '',\n declaration: true,\n\n // ng compiler to options\n enableResourceInlining: true,\n\n // these are required to set the appropriate EmitFlags\n flatModuleId: 'AUTOGENERATED',\n flatModuleOutFile: 'AUTOGENERATED',\n };\n\n const { readConfiguration } = await ngCompilerCli();\n\n return readConfiguration(fileName, extraOptions);\n}\n\n/**\n * Creates a parsed TypeScript configuration object.\n *\n * @param values File path or parsed configuration.\n */\nasync function createDefaultTsConfig(values?: ParsedConfiguration | string): Promise<ParsedConfiguration> {\n if (!values) {\n return readDefaultTsConfig();\n } else if (typeof values === 'string') {\n return readDefaultTsConfig(values);\n } else {\n return values;\n }\n}\n\n/**\n * Initializes TypeScript Compiler options and Angular Compiler options by overriding the\n * default config with entry point-specific values.\n */\nexport async function initializeTsConfig(\n defaultTsConfig: ParsedConfiguration | string | undefined,\n entryPoints: EntryPointNode[],\n): Promise<void> {\n const defaultTsConfigParsed = await createDefaultTsConfig(defaultTsConfig);\n if (defaultTsConfigParsed.errors.length > 0) {\n const { formatDiagnostics } = await ngCompilerCli();\n throw formatDiagnostics(defaultTsConfigParsed.errors);\n }\n\n if (defaultTsConfigParsed.options.enableIvy === false) {\n warn(\n 'Project is attempting to disable the Ivy compiler. ' +\n 'Angular versions 13 and higher do not support View Engine compiler for libraries. ' +\n 'The Ivy compiler will be used to build this project. ' +\n '\\nFor additional information or if the build fails, please see https://angular.io/guide/ivy',\n );\n\n defaultTsConfigParsed.options.enableIvy = true;\n defaultTsConfigParsed.options.compilationMode = 'partial';\n }\n\n entryPoints.forEach(currentEntryPoint => {\n const { entryPoint } = currentEntryPoint.data;\n log.debug(`Initializing tsconfig for ${entryPoint.moduleId}`);\n const basePath = path.dirname(entryPoint.entryFilePath);\n\n // Resolve defaults from DI token and create a deep copy of the defaults\n const tsConfig: ParsedConfiguration = JSON.parse(JSON.stringify(defaultTsConfigParsed));\n const overrideOptions: CompilerOptions = {\n flatModuleId: entryPoint.moduleId,\n flatModuleOutFile: `${entryPoint.flatModuleFile}.js`,\n basePath,\n rootDir: basePath,\n sourceRoot: '',\n };\n\n tsConfig.rootNames = [entryPoint.entryFilePath];\n tsConfig.options = { ...tsConfig.options, ...overrideOptions };\n currentEntryPoint.data.tsConfig = tsConfig;\n });\n}\n\n/**\n * Set the paths for entrypoint dependencies.\n *\n * This doesn't mutate the object.\n *\n * @param parsedTsConfig - A parsed tsconfig\n * @param entryPoints - A list of entryPoints\n * @param pointToSource Point the path mapping to either the source code or emitted declarations.\n * Typically for analysis one should point to the source files while for a compilation once should use the emitted declarations\n */\nexport function setDependenciesTsConfigPaths(\n parsedTsConfig: ParsedConfiguration,\n entryPoints: EntryPointNode[],\n pointToSource = false,\n): ParsedConfiguration {\n const tsConfig = JSON.parse(JSON.stringify(parsedTsConfig));\n\n // Add paths mappings for dependencies\n if (!tsConfig.options.paths) {\n tsConfig.options.paths = {};\n }\n\n for (const dep of entryPoints) {\n const { entryPoint } = dep.data;\n const { moduleId, destinationFiles, entryFilePath } = entryPoint;\n const mappedPath = [pointToSource ? entryFilePath : destinationFiles.declarations];\n\n if (!tsConfig.options.paths[moduleId]) {\n tsConfig.options.paths[moduleId] = mappedPath;\n } else {\n tsConfig.options.paths[moduleId].unshift(...mappedPath);\n }\n }\n\n return tsConfig;\n}\n"]}
1
+ {"version":3,"file":"tsconfig.js","sourceRoot":"","sources":["../../../src/lib/ts/tsconfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,4DAA4B;AAE5B,kDAAoC;AACpC,sCAAoC;AACpC,8DAAyD;AAE5C,QAAA,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,mBAAmB,CAAC,CAAC;AACrF;;GAEG;AACH,KAAK,UAAU,mBAAmB,CAAC,QAAQ,GAAG,2BAAmB;IAC/D,8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AAC,CAAC;IAE5D,sCAAsC;IACtC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE;QAC3B,QAAQ,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,CAAC;KAC7B;IAED,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE;QAC7B,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;QAChC,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,aAAa,EAAE,GAAG,UAAU,CAAC;QACjE,MAAM,UAAU,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;QAEnF,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;YACrC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;SAC/C;aAAM;YACL,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,CAAC;SACzD;KACF;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAzBD,oEAyBC","sourcesContent":["import type { CompilerOptions, ParsedConfiguration } from '@angular/compiler-cli';\nimport * as path from 'path';\nimport ts from 'typescript';\nimport { EntryPointNode } from '../ng-package/nodes';\nimport * as log from '../utils/log';\nimport { warn } from '../utils/log';\nimport { ngCompilerCli } from '../utils/ng-compiler-cli';\n\nexport const defaultTsConfigPath = path.join(__dirname, 'conf', 'tsconfig.ngc.json');\n/**\n * Reads the default TypeScript configuration.\n */\nasync function readDefaultTsConfig(fileName = defaultTsConfigPath): Promise<ParsedConfiguration> {\n // these options are mandatory\n const extraOptions: CompilerOptions = {\n moduleResolution: ts.ModuleResolutionKind.NodeJs,\n target: ts.ScriptTarget.ES2020,\n experimentalDecorators: true,\n\n // sourcemaps\n sourceMap: false,\n inlineSources: true,\n inlineSourceMap: true,\n\n outDir: '',\n declaration: true,\n\n // ng compiler to options\n enableResourceInlining: true,\n\n // these are required to set the appropriate EmitFlags\n flatModuleId: 'AUTOGENERATED',\n flatModuleOutFile: 'AUTOGENERATED',\n };\n\n const { readConfiguration } = await ngCompilerCli();\n\n return readConfiguration(fileName, extraOptions);\n}\n\n/**\n * Creates a parsed TypeScript configuration object.\n *\n * @param values File path or parsed configuration.\n */\nasync function createDefaultTsConfig(values?: ParsedConfiguration | string): Promise<ParsedConfiguration> {\n if (!values) {\n return readDefaultTsConfig();\n } else if (typeof values === 'string') {\n return readDefaultTsConfig(values);\n } else {\n return values;\n }\n}\n\n/**\n * Initializes TypeScript Compiler options and Angular Compiler options by overriding the\n * default config with entry point-specific values.\n */\nexport async function initializeTsConfig(\n defaultTsConfig: ParsedConfiguration | string | undefined,\n entryPoints: EntryPointNode[],\n): Promise<void> {\n const defaultTsConfigParsed = await createDefaultTsConfig(defaultTsConfig);\n if (defaultTsConfigParsed.errors.length > 0) {\n const { formatDiagnostics } = await ngCompilerCli();\n throw new Error(formatDiagnostics(defaultTsConfigParsed.errors));\n }\n\n if (defaultTsConfigParsed.options.enableIvy === false) {\n warn(\n 'Project is attempting to disable the Ivy compiler. ' +\n 'Angular versions 13 and higher do not support View Engine compiler for libraries. ' +\n 'The Ivy compiler will be used to build this project. ' +\n '\\nFor additional information or if the build fails, please see https://angular.io/guide/ivy',\n );\n\n defaultTsConfigParsed.options.enableIvy = true;\n defaultTsConfigParsed.options.compilationMode = 'partial';\n }\n\n entryPoints.forEach(currentEntryPoint => {\n const { entryPoint } = currentEntryPoint.data;\n log.debug(`Initializing tsconfig for ${entryPoint.moduleId}`);\n const basePath = path.dirname(entryPoint.entryFilePath);\n\n // Resolve defaults from DI token and create a deep copy of the defaults\n const tsConfig: ParsedConfiguration = JSON.parse(JSON.stringify(defaultTsConfigParsed));\n const overrideOptions: CompilerOptions = {\n flatModuleId: entryPoint.moduleId,\n flatModuleOutFile: `${entryPoint.flatModuleFile}.js`,\n basePath,\n rootDir: basePath,\n sourceRoot: '',\n };\n\n tsConfig.rootNames = [entryPoint.entryFilePath];\n tsConfig.options = { ...tsConfig.options, ...overrideOptions };\n currentEntryPoint.data.tsConfig = tsConfig;\n });\n}\n\n/**\n * Set the paths for entrypoint dependencies.\n *\n * This doesn't mutate the object.\n *\n * @param parsedTsConfig - A parsed tsconfig\n * @param entryPoints - A list of entryPoints\n * @param pointToSource Point the path mapping to either the source code or emitted declarations.\n * Typically for analysis one should point to the source files while for a compilation once should use the emitted declarations\n */\nexport function setDependenciesTsConfigPaths(\n parsedTsConfig: ParsedConfiguration,\n entryPoints: EntryPointNode[],\n pointToSource = false,\n): ParsedConfiguration {\n const tsConfig = JSON.parse(JSON.stringify(parsedTsConfig));\n\n // Add paths mappings for dependencies\n if (!tsConfig.options.paths) {\n tsConfig.options.paths = {};\n }\n\n for (const dep of entryPoints) {\n const { entryPoint } = dep.data;\n const { moduleId, destinationFiles, entryFilePath } = entryPoint;\n const mappedPath = [pointToSource ? entryFilePath : destinationFiles.declarations];\n\n if (!tsConfig.options.paths[moduleId]) {\n tsConfig.options.paths[moduleId] = mappedPath;\n } else {\n tsConfig.options.paths[moduleId].unshift(...mappedPath);\n }\n }\n\n return tsConfig;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng-packagr",
3
- "version": "13.0.0-rc.2",
3
+ "version": "13.0.2",
4
4
  "description": "Compile and package Angular libraries in Angular Package Format (APF)",
5
5
  "keywords": [
6
6
  "apf",
@@ -59,7 +59,7 @@
59
59
  "esbuild": "^0.13.0"
60
60
  },
61
61
  "peerDependencies": {
62
- "@angular/compiler-cli": "^13.0.0-next.0",
62
+ "@angular/compiler-cli": "^13.0.0 || ^13.1.0-next",
63
63
  "tslib": "^2.3.0",
64
64
  "typescript": "~4.4.0"
65
65
  }