ng-packagr 12.0.0-rc.2 → 12.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.
@@ -34,8 +34,7 @@ function analyseEntryPoint(graph, entryPoint, entryPoints) {
34
34
  ...entryPoint.data.tsConfig.options,
35
35
  skipLibCheck: true,
36
36
  noLib: true,
37
- allowJs: false,
38
- resolveJsonModule: false,
37
+ noEmit: true,
39
38
  types: [],
40
39
  target: ts.ScriptTarget.Latest,
41
40
  strict: false,
@@ -43,6 +42,9 @@ function analyseEntryPoint(graph, entryPoint, entryPoints) {
43
42
  const compilerHost = cache_compiler_host_1.cacheCompilerHost(graph, entryPoint, tsConfigOptions, moduleResolutionCache, undefined, analysesSourcesFileCache, false);
44
43
  const potentialDependencies = new Set();
45
44
  compilerHost.resolveModuleNames = (moduleNames, containingFile) => {
45
+ if (containingFile.endsWith('.d.ts')) {
46
+ return [].fill(undefined, 0, moduleNames.length);
47
+ }
46
48
  return moduleNames.map(moduleName => {
47
49
  if (!moduleName.startsWith('.')) {
48
50
  if (moduleName === primaryModuleId || moduleName.startsWith(`${primaryModuleId}/`)) {
@@ -1 +1 @@
1
- {"version":3,"file":"analyse-sources.transform.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/analyse-sources.transform.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,+BAA4B;AAC5B,8CAAqC;AACrC,oCAAgF;AAChF,sEAAiE;AAGjE,yCAAwC;AACxC,2CAAkD;AAErC,QAAA,uBAAuB,GAAc,WAAI,CACpD,eAAG,CAAC,KAAK,CAAC,EAAE;IACV,MAAM,WAAW,GAAqB,KAAK,CAAC,MAAM,CAAC,oBAAY,CAAC,CAAC;IACjE,MAAM,gBAAgB,GAAqB,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;IAEvF,KAAK,MAAM,UAAU,IAAI,gBAAgB,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EAAE;gBAC3B,MAAM,IAAI,KAAK,CAAC,eAAe,UAAU,uCAAuC,CAAC,CAAC;aACnF;YAED,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,KAAK,CAAC,CAAC,EAAE;gBACnC,MAAM,IAAI,KAAK,CAAC,eAAe,UAAU,iCAAiC,QAAQ,GAAG,CAAC,CAAC;aACxF;YAED,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;SAC3B;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,eAAe,UAAU,yBAAyB,QAAQ,kBAAkB,CAAC,CAAC;SAC/F;KACF;AACH,CAAC","sourcesContent":["import * as ts from 'typescript';\nimport { pipe } from 'rxjs';\nimport { map } from 'rxjs/operators';\nimport { isEntryPoint, EntryPointNode, isPackage, PackageNode } from '../nodes';\nimport { cacheCompilerHost } from '../../ts/cache-compiler-host';\nimport { BuildGraph } from '../../graph/build-graph';\nimport { Transform } from '../../graph/transform';\nimport { debug } from '../../utils/log';\nimport { ensureUnixPath } from '../../utils/path';\n\nexport const analyseSourcesTransform: Transform = pipe(\n map(graph => {\n const entryPoints: EntryPointNode[] = graph.filter(isEntryPoint);\n const dirtyEntryPoints: EntryPointNode[] = entryPoints.filter(x => x.state !== 'done');\n\n for (const entryPoint of dirtyEntryPoints) {\n analyseEntryPoint(graph, entryPoint, entryPoints);\n }\n\n return graph;\n }),\n);\n\n/**\n * Analyses an entrypoint, searching for TypeScript dependencies and additional resources (Templates and Stylesheets).\n *\n * @param graph Build graph\n * @param entryPoint Current entry point that should be analysed.\n * @param entryPoints List of all entry points.\n */\nfunction analyseEntryPoint(graph: BuildGraph, entryPoint: EntryPointNode, entryPoints: EntryPointNode[]) {\n const { oldPrograms, analysesSourcesFileCache, moduleResolutionCache } = entryPoint.cache;\n const oldProgram = oldPrograms && (oldPrograms['analysis'] as ts.Program | undefined);\n const { moduleId } = entryPoint.data.entryPoint;\n const packageNode: PackageNode = graph.find(isPackage);\n const primaryModuleId = packageNode.data.primary.moduleId;\n\n debug(`Analysing sources for ${moduleId}`);\n const tsConfigOptions: ts.CompilerOptions = {\n ...entryPoint.data.tsConfig.options,\n skipLibCheck: true,\n noLib: true,\n allowJs: false,\n resolveJsonModule: false,\n types: [],\n target: ts.ScriptTarget.Latest,\n strict: false,\n };\n\n const compilerHost = cacheCompilerHost(\n graph,\n entryPoint,\n tsConfigOptions,\n moduleResolutionCache,\n undefined,\n analysesSourcesFileCache,\n false,\n );\n\n const potentialDependencies = new Set<string>();\n\n compilerHost.resolveModuleNames = (moduleNames: string[], containingFile: string) => {\n return moduleNames.map(moduleName => {\n if (!moduleName.startsWith('.')) {\n if (moduleName === primaryModuleId || moduleName.startsWith(`${primaryModuleId}/`)) {\n potentialDependencies.add(moduleName);\n }\n\n return undefined;\n }\n\n const { resolvedModule } = ts.resolveModuleName(\n moduleName,\n ensureUnixPath(containingFile),\n tsConfigOptions,\n compilerHost,\n moduleResolutionCache,\n );\n\n return resolvedModule;\n });\n };\n\n const program: ts.Program = ts.createProgram(\n entryPoint.data.tsConfig.rootNames,\n tsConfigOptions,\n compilerHost,\n oldProgram,\n );\n\n debug(`tsc program structure is reused: ${oldProgram ? (oldProgram as any).structureIsReused : 'No old program'}`);\n\n entryPoint.cache.oldPrograms = { ...entryPoint.cache.oldPrograms, ['analysis']: program };\n\n const entryPointsMapped: Record<string, EntryPointNode> = {};\n for (const dep of entryPoints) {\n entryPointsMapped[dep.data.entryPoint.moduleId] = dep;\n }\n\n for (const moduleName of potentialDependencies) {\n const dep = entryPointsMapped[moduleName];\n\n if (dep) {\n debug(`Found entry point dependency: ${moduleId} -> ${moduleName}`);\n\n if (moduleId === moduleName) {\n throw new Error(`Entry point ${moduleName} has a circular dependency on itself.`);\n }\n\n if (dep.some(n => entryPoint === n)) {\n throw new Error(`Entry point ${moduleName} has a circular dependency on ${moduleId}.`);\n }\n\n entryPoint.dependsOn(dep);\n } else {\n throw new Error(`Entry point ${moduleName} which is required by ${moduleId} doesn't exists.`);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"analyse-sources.transform.js","sourceRoot":"","sources":["../../../../src/lib/ng-package/entry-point/analyse-sources.transform.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,+BAA4B;AAC5B,8CAAqC;AACrC,oCAAgF;AAChF,sEAAiE;AAGjE,yCAAwC;AACxC,2CAAkD;AAErC,QAAA,uBAAuB,GAAc,WAAI,CACpD,eAAG,CAAC,KAAK,CAAC,EAAE;IACV,MAAM,WAAW,GAAqB,KAAK,CAAC,MAAM,CAAC,oBAAY,CAAC,CAAC;IACjE,MAAM,gBAAgB,GAAqB,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;IAEvF,KAAK,MAAM,UAAU,IAAI,gBAAgB,EAAE;QACzC,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;KACnD;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC,CACH,CAAC;AAEF;;;;;;GAMG;AACH,SAAS,iBAAiB,CAAC,KAAiB,EAAE,UAA0B,EAAE,WAA6B;IACrG,MAAM,EAAE,WAAW,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC;IAC1F,MAAM,UAAU,GAAG,WAAW,IAAK,WAAW,CAAC,UAAU,CAA4B,CAAC;IACtF,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;IAChD,MAAM,WAAW,GAAgB,KAAK,CAAC,IAAI,CAAC,iBAAS,CAAC,CAAC;IACvD,MAAM,eAAe,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAE1D,WAAK,CAAC,yBAAyB,QAAQ,EAAE,CAAC,CAAC;IAC3C,MAAM,eAAe,GAAuB;QAC1C,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,C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CAAC;IAEF,WAAK,CAAC,oCAAoC,UAAU,CAAC,CAAC,CAAE,UAAkB,CAAC,iBAAiB,CAAC,CAAC,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAEnH,UAAU,CAAC,KAAK,CAAC,WAAW,GAAG,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC;IAE1F,MAAM,iBAAiB,GAAmC,EAAE,CAAC;IAC7D,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE;QAC7B,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC;KACvD;IAED,KAAK,MAAM,UAAU,IAAI,qBAAqB,EAAE;QAC9C,MAAM,GAAG,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAE1C,IAAI,GAAG,EAAE;YACP,WAAK,CAAC,iCAAiC,QAAQ,OAAO,UAAU,EAAE,CAAC,CAAC;YAEpE,IAAI,QAAQ,KAAK,UAAU,EAAE;gBAC3B,MAAM,IAAI,KAAK,CAAC,eAAe,UAAU,uCAAuC,CAAC,CAAC;aACnF;YAED,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,KAAK,CAAC,CAAC,EAAE;gBACnC,MAAM,IAAI,KAAK,CAAC,eAAe,UAAU,iCAAiC,QAAQ,GAAG,CAAC,CAAC;aACxF;YAED,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;SAC3B;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,eAAe,UAAU,yBAAyB,QAAQ,kBAAkB,CAAC,CAAC;SAC/F;KACF;AACH,CAAC","sourcesContent":["import * as ts from 'typescript';\nimport { pipe } from 'rxjs';\nimport { map } from 'rxjs/operators';\nimport { isEntryPoint, EntryPointNode, isPackage, PackageNode } from '../nodes';\nimport { cacheCompilerHost } from '../../ts/cache-compiler-host';\nimport { BuildGraph } from '../../graph/build-graph';\nimport { Transform } from '../../graph/transform';\nimport { debug } from '../../utils/log';\nimport { ensureUnixPath } from '../../utils/path';\n\nexport const analyseSourcesTransform: Transform = pipe(\n map(graph => {\n const entryPoints: EntryPointNode[] = graph.filter(isEntryPoint);\n const dirtyEntryPoints: EntryPointNode[] = entryPoints.filter(x => x.state !== 'done');\n\n for (const entryPoint of dirtyEntryPoints) {\n analyseEntryPoint(graph, entryPoint, entryPoints);\n }\n\n return graph;\n }),\n);\n\n/**\n * Analyses an entrypoint, searching for TypeScript dependencies and additional resources (Templates and Stylesheets).\n *\n * @param graph Build graph\n * @param entryPoint Current entry point that should be analysed.\n * @param entryPoints List of all entry points.\n */\nfunction analyseEntryPoint(graph: BuildGraph, entryPoint: EntryPointNode, entryPoints: EntryPointNode[]) {\n const { oldPrograms, analysesSourcesFileCache, moduleResolutionCache } = entryPoint.cache;\n const oldProgram = oldPrograms && (oldPrograms['analysis'] as ts.Program | undefined);\n const { moduleId } = entryPoint.data.entryPoint;\n const packageNode: PackageNode = graph.find(isPackage);\n const primaryModuleId = packageNode.data.primary.moduleId;\n\n debug(`Analysing sources for ${moduleId}`);\n const tsConfigOptions: ts.CompilerOptions = {\n ...entryPoint.data.tsConfig.options,\n skipLibCheck: true,\n noLib: true,\n noEmit: true,\n types: [],\n target: ts.ScriptTarget.Latest,\n strict: false,\n };\n\n const compilerHost = cacheCompilerHost(\n graph,\n entryPoint,\n tsConfigOptions,\n moduleResolutionCache,\n undefined,\n analysesSourcesFileCache,\n false,\n );\n\n const potentialDependencies = new Set<string>();\n\n compilerHost.resolveModuleNames = (moduleNames: string[], containingFile: string) => {\n if (containingFile.endsWith('.d.ts')) {\n return [].fill(undefined, 0, moduleNames.length);\n }\n\n return moduleNames.map(moduleName => {\n if (!moduleName.startsWith('.')) {\n if (moduleName === primaryModuleId || moduleName.startsWith(`${primaryModuleId}/`)) {\n potentialDependencies.add(moduleName);\n }\n\n return undefined;\n }\n\n const { resolvedModule } = ts.resolveModuleName(\n moduleName,\n ensureUnixPath(containingFile),\n tsConfigOptions,\n compilerHost,\n moduleResolutionCache,\n );\n\n return resolvedModule;\n });\n };\n\n const program: ts.Program = ts.createProgram(\n entryPoint.data.tsConfig.rootNames,\n tsConfigOptions,\n compilerHost,\n oldProgram,\n );\n\n debug(`tsc program structure is reused: ${oldProgram ? (oldProgram as any).structureIsReused : 'No old program'}`);\n\n entryPoint.cache.oldPrograms = { ...entryPoint.cache.oldPrograms, ['analysis']: program };\n\n const entryPointsMapped: Record<string, EntryPointNode> = {};\n for (const dep of entryPoints) {\n entryPointsMapped[dep.data.entryPoint.moduleId] = dep;\n }\n\n for (const moduleName of potentialDependencies) {\n const dep = entryPointsMapped[moduleName];\n\n if (dep) {\n debug(`Found entry point dependency: ${moduleId} -> ${moduleName}`);\n\n if (moduleId === moduleName) {\n throw new Error(`Entry point ${moduleName} has a circular dependency on itself.`);\n }\n\n if (dep.some(n => entryPoint === n)) {\n throw new Error(`Entry point ${moduleName} has a circular dependency on ${moduleId}.`);\n }\n\n entryPoint.dependsOn(dep);\n } else {\n throw new Error(`Entry point ${moduleName} which is required by ${moduleId} doesn't exists.`);\n }\n }\n}\n"]}
@@ -10,27 +10,31 @@ const worker_threads_1 = require("worker_threads");
10
10
  const postcssPresetEnv = require("postcss-preset-env");
11
11
  const stylesheet_processor_1 = require("./stylesheet-processor");
12
12
  const fs_1 = require("../utils/fs");
13
- const ngPackagrVersion = require('../../../package.json').version;
13
+ const ngPackagrVersion = require('../../package.json').version;
14
14
  async function processCss({ filePath, browserslistData, cssUrl, styleIncludePaths, basePath, cachePath, }) {
15
15
  const content = await fs_1.readFile(filePath, 'utf8');
16
+ let key;
17
+ if (!content.includes('@import') && !content.includes('@use')) {
18
+ // No transitive deps, we can cache more aggressively.
19
+ key = generateKey(content, browserslistData);
20
+ const result = await readCacheEntry(cachePath, key);
21
+ if (result) {
22
+ return result;
23
+ }
24
+ }
16
25
  // Render pre-processor language (sass, styl, less)
17
26
  const renderedCss = await renderCss(filePath, content, basePath, styleIncludePaths);
18
- // Render postcss (autoprefixing and friends)
19
- const result = await optimizeCss(filePath, renderedCss, browserslistData, cssUrl);
20
27
  // We cannot cache CSS re-rendering phase, because a transitive dependency via (@import) can case different CSS output.
21
28
  // Example a change in a mixin or SCSS variable.
22
- const key = crypto_1.createHash('sha1')
23
- .update(ngPackagrVersion)
24
- .update(result.css)
25
- .update(browserslistData.join(''))
26
- .digest('base64');
27
- const entry = await cacache.get.info(cachePath, key);
28
- if (entry) {
29
- return {
30
- css: await fs_1.readFile(entry.path, 'utf8'),
31
- warnings: [],
32
- };
29
+ if (!key) {
30
+ key = generateKey(renderedCss, browserslistData);
31
+ const cachedResult = await readCacheEntry(cachePath, key);
32
+ if (cachedResult) {
33
+ return cachedResult;
34
+ }
33
35
  }
36
+ // Render postcss (autoprefixing and friends)
37
+ const result = await optimizeCss(filePath, renderedCss, browserslistData, cssUrl);
34
38
  // Add to cache
35
39
  await cacache.put(cachePath, key, result.css);
36
40
  return {
@@ -122,6 +126,19 @@ function optimizeCss(filePath, css, browsers, cssUrl) {
122
126
  to: filePath.replace(path.extname(filePath), '.css'),
123
127
  });
124
128
  }
129
+ function generateKey(content, browserslistData) {
130
+ return crypto_1.createHash('sha1').update(ngPackagrVersion).update(content).update(browserslistData.join('')).digest('base64');
131
+ }
132
+ async function readCacheEntry(cachePath, key) {
133
+ const entry = await cacache.get.info(cachePath, key);
134
+ if (entry) {
135
+ return {
136
+ css: await fs_1.readFile(entry.path, 'utf8'),
137
+ warnings: [],
138
+ };
139
+ }
140
+ return undefined;
141
+ }
125
142
  worker_threads_1.parentPort.on('message', async ({ signal, port, workerOptions }) => {
126
143
  try {
127
144
  const result = await processCss(workerOptions);
@@ -1 +1 @@
1
- {"version":3,"file":"stylesheet-processor-worker.js","sourceRoot":"","sources":["../../../src/lib/styles/stylesheet-processor-worker.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AACnC,mCAAoC;AACpC,6BAA6B;AAC7B,qC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AE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,EAAE;IACjE,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,aAAa,CAAC,CAAC;QAC/C,IAAI,CAAC,WAAW,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;KACjC;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;KAC5C;YAAS;QACR,qCAAqC;QACrC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC1B,yBAAyB;QACzB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;KACd;AACH,CAAC,CAAC,CAAC","sourcesContent":["import * as cacache from 'cacache';\nimport { createHash } from 'crypto';\nimport * as path from 'path';\nimport postcss, { LazyResult } from 'postcss';\nimport * as postcssUrl from 'postcss-url';\nimport * as cssnano from 'cssnano';\nimport { parentPort } from 'worker_threads';\nimport * as postcssPresetEnv from 'postcss-preset-env';\n\nimport { CssUrl, WorkerOptions, WorkerResult } from './stylesheet-processor';\nimport { readFile } from '../utils/fs';\n\nconst ngPackagrVersion = require('../../../package.json').version;\n\nasync function processCss({\n filePath,\n browserslistData,\n cssUrl,\n styleIncludePaths,\n basePath,\n cachePath,\n}: WorkerOptions): Promise<WorkerResult> {\n const content = await readFile(filePath, 'utf8');\n\n // Render pre-processor language (sass, styl, less)\n const renderedCss = await renderCss(filePath, content, basePath, styleIncludePaths);\n\n // Render postcss (autoprefixing and friends)\n const result = await optimizeCss(filePath, renderedCss, browserslistData, cssUrl);\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 const key = createHash('sha1')\n .update(ngPackagrVersion)\n .update(result.css)\n .update(browserslistData.join(''))\n .digest('base64');\n\n const entry = await cacache.get.info(cachePath, key);\n if (entry) {\n return {\n css: await readFile(entry.path, 'utf8'),\n warnings: [],\n };\n }\n\n // Add to cache\n await cacache.put(cachePath, key, result.css);\n\n return {\n css: result.css,\n warnings: result.warnings().map(w => w.toString()),\n };\n}\n\nasync function renderCss(filePath: string, css: string, basePath, styleIncludePaths?: string[]): Promise<string> {\n const ext = path.extname(filePath);\n\n switch (ext) {\n case '.sass':\n case '.scss': {\n /*\n * Please be aware of the few differences in behaviour https://github.com/sass/dart-sass/blob/master/README.md#behavioral-differences-from-ruby-sass\n * By default `npm install` will install sass.\n * To use node-sass you need to use:\n * Npm:\n * `npm install node-sass --save-dev`\n * Yarn:\n * `yarn add node-sass --dev`\n */\n let sassCompiler: any | undefined;\n try {\n sassCompiler = require('node-sass'); // Check if node-sass is explicitly included.\n } catch {\n sassCompiler = await import('sass');\n }\n\n return sassCompiler\n .renderSync({\n file: filePath,\n data: css,\n indentedSyntax: '.sass' === ext,\n importer: await import('node-sass-tilde-importer'),\n includePaths: styleIncludePaths,\n })\n .css.toString();\n }\n case '.less': {\n const { css: content } = await (await import('less')).render(css, {\n filename: filePath,\n javascriptEnabled: true,\n paths: styleIncludePaths,\n });\n\n return content;\n }\n case '.styl':\n case '.stylus': {\n const stylus = await import('stylus');\n\n return (\n stylus(css)\n // add paths for resolve\n .set('paths', [basePath, '.', ...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\nfunction optimizeCss(filePath: string, css: string, browsers: string[], cssUrl?: CssUrl): LazyResult {\n const postCssPlugins = [];\n\n if (cssUrl !== CssUrl.none) {\n postCssPlugins.push(postcssUrl({ url: cssUrl }));\n }\n\n postCssPlugins.push(\n postcssPresetEnv({\n browsers,\n autoprefixer: true,\n stage: 3,\n }),\n cssnano({\n preset: [\n 'default',\n {\n // Disable SVG optimizations, as this can cause optimizations which are not compatible in all browsers.\n svgo: false,\n // Disable `calc` optimizations, due to several issues. #16910, #16875, #17890\n calc: false,\n // Disable CSS rules sorted due to several issues #20693, https://github.com/ionic-team/ionic-framework/issues/23266 and https://github.com/cssnano/cssnano/issues/1054\n cssDeclarationSorter: false,\n },\n ],\n }),\n );\n\n return postcss(postCssPlugins).process(css, {\n from: filePath,\n to: filePath.replace(path.extname(filePath), '.css'),\n });\n}\n\nparentPort.on('message', async ({ signal, port, workerOptions }) => {\n try {\n const result = await processCss(workerOptions);\n port.postMessage({ ...result });\n } catch (error) {\n port.postMessage({ error: error.message });\n } finally {\n // Change the value of signal[0] to 1\n Atomics.add(signal, 0, 1);\n // Unlock the main thread\n Atomics.notify(signal, 0);\n port.close();\n }\n});\n"]}
1
+ {"version":3,"file":"stylesheet-processor-worker.js","sourceRoot":"","sources":["../../../src/lib/styles/stylesheet-processor-worker.ts"],"names":[],"mappings":";;AAAA,mCAAmC;AACnC,mCAAoC;AACpC,6BAA6B;AAC7B,qCAA8C;AAC9C,0CAA0C;AAC1C,mCAAmC;AACnC,mDAA4C;AAC5C,uDAAuD;AAEvD,iEAA6E;AAC7E,oCAAuC;AAEvC,MAAM,gBAAgB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC;AAE/D,KAAK,UAAU,UAAU,CAAC,EACxB,QAAQ,EACR,gBAAgB,EAChB,MAAM,EACN,iBAAiB,EACjB,QAAQ,EACR,SAAS,GACK;IACd,MAAM,OAAO,GAAG,MAAM,aAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjD,IAAI,GAAuB,CAAC;IAE5B,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC7D,sDAAsD;QACtD,GAAG,GAAG,WAAW,CAAC,OAAO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IAAI,EAAE,MAAM,CAAC;YACvC,QAAQ,EAAE,EAAE;SACb,CAAC;KACH;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,2BAAU,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,EAAE;IACjE,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,aAAa,CAAC,CAAC;QAC/C,IAAI,CAAC,WAAW,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;KACjC;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;KAC5C;YAAS;QACR,qCAAqC;QACrC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC1B,yBAAyB;QACzB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,KAAK,EAAE,CAAC;KACd;AACH,CAAC,CAAC,CAAC","sourcesContent":["import * as cacache from 'cacache';\nimport { createHash } from 'crypto';\nimport * as path from 'path';\nimport postcss, { LazyResult } from 'postcss';\nimport * as postcssUrl from 'postcss-url';\nimport * as cssnano from 'cssnano';\nimport { parentPort } from 'worker_threads';\nimport * as postcssPresetEnv from 'postcss-preset-env';\n\nimport { CssUrl, WorkerOptions, WorkerResult } from './stylesheet-processor';\nimport { readFile } from '../utils/fs';\n\nconst ngPackagrVersion = require('../../package.json').version;\n\nasync function processCss({\n filePath,\n browserslistData,\n cssUrl,\n styleIncludePaths,\n basePath,\n cachePath,\n}: WorkerOptions): Promise<WorkerResult> {\n const content = await readFile(filePath, 'utf8');\n let key: string | undefined;\n\n if (!content.includes('@import') && !content.includes('@use')) {\n // No transitive deps, we can cache more aggressively.\n key = generateKey(content, browserslistData);\n const result = await readCacheEntry(cachePath, key);\n if (result) {\n return result;\n }\n }\n\n // Render pre-processor language (sass, styl, less)\n const renderedCss = await renderCss(filePath, content, basePath, styleIncludePaths);\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 = generateKey(renderedCss, browserslistData);\n\n const cachedResult = await readCacheEntry(cachePath, key);\n if (cachedResult) {\n return cachedResult;\n }\n }\n\n // Render postcss (autoprefixing and friends)\n const result = await optimizeCss(filePath, renderedCss, browserslistData, cssUrl);\n\n // Add to cache\n await cacache.put(cachePath, key, result.css);\n\n return {\n css: result.css,\n warnings: result.warnings().map(w => w.toString()),\n };\n}\n\nasync function renderCss(\n filePath: string,\n css: string,\n basePath: string,\n styleIncludePaths?: string[],\n): Promise<string> {\n const ext = path.extname(filePath);\n\n switch (ext) {\n case '.sass':\n case '.scss': {\n /*\n * Please be aware of the few differences in behaviour https://github.com/sass/dart-sass/blob/master/README.md#behavioral-differences-from-ruby-sass\n * By default `npm install` will install sass.\n * To use node-sass you need to use:\n * Npm:\n * `npm install node-sass --save-dev`\n * Yarn:\n * `yarn add node-sass --dev`\n */\n let sassCompiler: any | undefined;\n try {\n sassCompiler = require('node-sass'); // Check if node-sass is explicitly included.\n } catch {\n sassCompiler = await import('sass');\n }\n\n return sassCompiler\n .renderSync({\n file: filePath,\n data: css,\n indentedSyntax: '.sass' === ext,\n importer: await import('node-sass-tilde-importer'),\n includePaths: styleIncludePaths,\n })\n .css.toString();\n }\n case '.less': {\n const { css: content } = await (await import('less')).render(css, {\n filename: filePath,\n javascriptEnabled: true,\n paths: styleIncludePaths,\n });\n\n return content;\n }\n case '.styl':\n case '.stylus': {\n const stylus = await import('stylus');\n\n return (\n stylus(css)\n // add paths for resolve\n .set('paths', [basePath, '.', ...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\nfunction optimizeCss(filePath: string, css: string, browsers: string[], cssUrl?: CssUrl): LazyResult {\n const postCssPlugins = [];\n\n if (cssUrl !== CssUrl.none) {\n postCssPlugins.push(postcssUrl({ url: cssUrl }));\n }\n\n postCssPlugins.push(\n postcssPresetEnv({\n browsers,\n autoprefixer: true,\n stage: 3,\n }),\n cssnano({\n preset: [\n 'default',\n {\n // Disable SVG optimizations, as this can cause optimizations which are not compatible in all browsers.\n svgo: false,\n // Disable `calc` optimizations, due to several issues. #16910, #16875, #17890\n calc: false,\n // Disable CSS rules sorted due to several issues #20693, https://github.com/ionic-team/ionic-framework/issues/23266 and https://github.com/cssnano/cssnano/issues/1054\n cssDeclarationSorter: false,\n },\n ],\n }),\n );\n\n return postcss(postCssPlugins).process(css, {\n from: filePath,\n to: filePath.replace(path.extname(filePath), '.css'),\n });\n}\n\nfunction generateKey(content: string, browserslistData: string[]): string {\n return createHash('sha1').update(ngPackagrVersion).update(content).update(browserslistData.join('')).digest('base64');\n}\n\nasync function readCacheEntry(cachePath: string, key: string): Promise<WorkerResult | undefined> {\n const entry = await cacache.get.info(cachePath, key);\n if (entry) {\n return {\n css: await readFile(entry.path, 'utf8'),\n warnings: [],\n };\n }\n\n return undefined;\n}\n\nparentPort.on('message', async ({ signal, port, workerOptions }) => {\n try {\n const result = await processCss(workerOptions);\n port.postMessage({ ...result });\n } catch (error) {\n port.postMessage({ error: error.message });\n } finally {\n // Change the value of signal[0] to 1\n Atomics.add(signal, 0, 1);\n // Unlock the main thread\n Atomics.notify(signal, 0);\n port.close();\n }\n});\n"]}
@@ -5,6 +5,7 @@ const ts = require("typescript");
5
5
  const ng = require("@angular/compiler-cli");
6
6
  const path = require("path");
7
7
  const path_1 = require("../utils/path");
8
+ const log_1 = require("../utils/log");
8
9
  const nodes_1 = require("../ng-package/nodes");
9
10
  const node_1 = require("../graph/node");
10
11
  function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionCache, stylesheetProcessor, sourcesFileCache = entryPoint.cache.sourcesFileCache, setParentNodes = true) {
@@ -88,7 +89,13 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
88
89
  }
89
90
  else {
90
91
  // stylesheet
91
- cache.content = stylesheetProcessor.process(fileName);
92
+ try {
93
+ cache.content = stylesheetProcessor.process(fileName);
94
+ }
95
+ catch (err) {
96
+ log_1.error('\n' + err.message + ` in stylesheet file ${fileName}.`);
97
+ throw err;
98
+ }
92
99
  }
93
100
  if (cache.content === undefined) {
94
101
  throw new Error(`Cannot read file ${fileName}.`);
@@ -1 +1 @@
1
- {"version":3,"file":"cache-compiler-host.js","sourceRoot":"","sources":["../../../src/lib/ts/cache-compiler-host.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,4CAA4C;AAC5C,6BAA6B;AAC7B,wCAA+C;AAE/C,+CAA8D;AAG9D,wCAAqC;AAErC,SAAgB,iBAAiB,CAC/B,KAAiB,EACjB,UAA0B,EAC1B,eAAmC,EACnC,qBAA+C,EAC/C,mBAAyC,EACzC,mBAA8B,UAAU,CAAC,KAAK,CAAC,gBAAgB,EAC/D,cAAc,GAAG,IAAI;IAErB,MAAM,MAAM,GAAG,EAAE,CAAC,kBAAkB,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;IACtE,MAAM,YAAY,GAAG,EAAE,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,CAAC,CAAC;IAEjF,MAAM,OAAO,GAAG,CAAC,QAAgB,EAAE,EAAE;QACnC,MAAM,OAAO,GAAG,eAAO,CAAC,qBAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;QAClD,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE9B,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,GAAG,IAAI,WAAI,CAAC,OAAO,CAAC,CAAC;YACzB,KAAK,CAAC,GAAG,CAAC,IAAI,C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as path from 'path';\nimport { ensureUnixPath } from '../utils/path';\nimport { StylesheetProcessor } from '../styles/stylesheet-processor';\nimport { EntryPointNode, fileUrl } from '../ng-package/nodes';\nimport { BuildGraph } from '../graph/build-graph';\nimport { FileCache } from '../file-system/file-cache';\nimport { Node } from '../graph/node';\n\nexport function cacheCompilerHost(\n graph: BuildGraph,\n entryPoint: EntryPointNode,\n compilerOptions: ng.CompilerOptions,\n moduleResolutionCache: ts.ModuleResolutionCache,\n stylesheetProcessor?: StylesheetProcessor,\n sourcesFileCache: FileCache = entryPoint.cache.sourcesFileCache,\n setParentNodes = true,\n): ng.CompilerHost {\n const tsHost = ts.createCompilerHost(compilerOptions, setParentNodes);\n const compilerHost = ng.createCompilerHost({ options: compilerOptions, tsHost });\n\n const getNode = (fileName: string) => {\n const nodeUri = fileUrl(ensureUnixPath(fileName));\n let node = graph.get(nodeUri);\n\n if (!node) {\n node = new Node(nodeUri);\n graph.put(node);\n }\n\n return node;\n };\n\n const addDependee = (fileName: string) => {\n const node = getNode(fileName);\n entryPoint.dependsOn(node);\n };\n\n return {\n ...compilerHost,\n\n // ts specific\n fileExists: (fileName: string) => {\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.exists === undefined) {\n cache.exists = compilerHost.fileExists.call(this, fileName);\n }\n return cache.exists;\n },\n\n getSourceFile: (fileName: string, languageVersion: ts.ScriptTarget) => {\n addDependee(fileName);\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (!cache.sourceFile) {\n cache.sourceFile = compilerHost.getSourceFile.call(this, fileName, languageVersion);\n }\n return cache.sourceFile;\n },\n\n writeFile: (\n fileName: string,\n data: string,\n writeByteOrderMark: boolean,\n onError?: (message: string) => void,\n sourceFiles?: ReadonlyArray<ts.SourceFile>,\n ) => {\n if (fileName.endsWith('.d.ts')) {\n sourceFiles.forEach(source => {\n const cache = sourcesFileCache.getOrCreate(source.fileName);\n if (!cache.declarationFileName) {\n cache.declarationFileName = ensureUnixPath(fileName);\n }\n });\n }\n\n compilerHost.writeFile.call(this, fileName, data, writeByteOrderMark, onError, sourceFiles);\n },\n\n readFile: (fileName: string) => {\n addDependee(fileName);\n\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n cache.content = compilerHost.readFile.call(this, fileName);\n }\n return cache.content;\n },\n\n // ng specific\n moduleNameToFileName: (moduleName: string, containingFile: string) => {\n const { resolvedModule } = ts.resolveModuleName(\n moduleName,\n ensureUnixPath(containingFile),\n compilerOptions,\n compilerHost,\n moduleResolutionCache,\n );\n\n return resolvedModule && resolvedModule.resolvedFileName;\n },\n\n resolveModuleNames: (moduleNames: string[], containingFile: string) => {\n return moduleNames.map(moduleName => {\n const { resolvedModule } = ts.resolveModuleName(\n moduleName,\n ensureUnixPath(containingFile),\n compilerOptions,\n compilerHost,\n moduleResolutionCache,\n );\n\n return resolvedModule;\n });\n },\n\n resourceNameToFileName: (resourceName: string, containingFilePath: string) => {\n const resourcePath = path.resolve(path.dirname(containingFilePath), resourceName);\n const containingNode = getNode(containingFilePath);\n const resourceNode = getNode(resourcePath);\n containingNode.dependsOn(resourceNode);\n\n return resourcePath;\n },\n\n readResource: (fileName: string) => {\n addDependee(fileName);\n\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n if (/(html|htm|svg)$/.test(path.extname(fileName))) {\n // template\n cache.content = compilerHost.readFile.call(this, fileName);\n } else {\n // stylesheet\n cache.content = stylesheetProcessor.process(fileName);\n }\n\n if (cache.content === undefined) {\n throw new Error(`Cannot read file ${fileName}.`);\n };\n\n cache.exists = true;\n }\n\n return cache.content;\n },\n };\n}\n"]}
1
+ {"version":3,"file":"cache-compiler-host.js","sourceRoot":"","sources":["../../../src/lib/ts/cache-compiler-host.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,4CAA4C;AAC5C,6BAA6B;AAC7B,wCAA+C;AAC/C,sCAAqC;AAErC,+CAA8D;AAG9D,wCAAqC;AAErC,SAAgB,iBAAiB,CAC/B,KA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/B,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE;oBAClD,WAAW;oBACX,KAAK,CAAC,OAAO,GAAG,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;iBAC5D;qBAAM;oBACL,aAAa;oBACb,IAAI;wBACF,KAAK,CAAC,OAAO,GAAG,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;qBACvD;oBAAC,OAAO,GAAG,EAAE;wBACZ,WAAK,CAAC,IAAI,GAAG,GAAG,CAAC,OAAO,GAAG,uBAAuB,QAAQ,GAAG,CAAC,CAAC;wBAC/D,MAAM,GAAG,CAAC;qBACX;iBACF;gBAED,IAAI,KAAK,CAAC,OAAO,KAAK,SAAS,EAAE;oBAC/B,MAAM,IAAI,KAAK,CAAC,oBAAoB,QAAQ,GAAG,CAAC,CAAC;iBAClD;gBAAA,CAAC;gBAEF,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;aACrB;YAED,OAAO,KAAK,CAAC,OAAO,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC;AA/ID,8CA+IC","sourcesContent":["import * as ts from 'typescript';\nimport * as ng from '@angular/compiler-cli';\nimport * as path from 'path';\nimport { ensureUnixPath } from '../utils/path';\nimport { error } from '../utils/log';\nimport { StylesheetProcessor } from '../styles/stylesheet-processor';\nimport { EntryPointNode, fileUrl } from '../ng-package/nodes';\nimport { BuildGraph } from '../graph/build-graph';\nimport { FileCache } from '../file-system/file-cache';\nimport { Node } from '../graph/node';\n\nexport function cacheCompilerHost(\n graph: BuildGraph,\n entryPoint: EntryPointNode,\n compilerOptions: ng.CompilerOptions,\n moduleResolutionCache: ts.ModuleResolutionCache,\n stylesheetProcessor?: StylesheetProcessor,\n sourcesFileCache: FileCache = entryPoint.cache.sourcesFileCache,\n setParentNodes = true,\n): ng.CompilerHost {\n const tsHost = ts.createCompilerHost(compilerOptions, setParentNodes);\n const compilerHost = ng.createCompilerHost({ options: compilerOptions, tsHost });\n\n const getNode = (fileName: string) => {\n const nodeUri = fileUrl(ensureUnixPath(fileName));\n let node = graph.get(nodeUri);\n\n if (!node) {\n node = new Node(nodeUri);\n graph.put(node);\n }\n\n return node;\n };\n\n const addDependee = (fileName: string) => {\n const node = getNode(fileName);\n entryPoint.dependsOn(node);\n };\n\n return {\n ...compilerHost,\n\n // ts specific\n fileExists: (fileName: string) => {\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.exists === undefined) {\n cache.exists = compilerHost.fileExists.call(this, fileName);\n }\n return cache.exists;\n },\n\n getSourceFile: (fileName: string, languageVersion: ts.ScriptTarget) => {\n addDependee(fileName);\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (!cache.sourceFile) {\n cache.sourceFile = compilerHost.getSourceFile.call(this, fileName, languageVersion);\n }\n return cache.sourceFile;\n },\n\n writeFile: (\n fileName: string,\n data: string,\n writeByteOrderMark: boolean,\n onError?: (message: string) => void,\n sourceFiles?: ReadonlyArray<ts.SourceFile>,\n ) => {\n if (fileName.endsWith('.d.ts')) {\n sourceFiles.forEach(source => {\n const cache = sourcesFileCache.getOrCreate(source.fileName);\n if (!cache.declarationFileName) {\n cache.declarationFileName = ensureUnixPath(fileName);\n }\n });\n }\n\n compilerHost.writeFile.call(this, fileName, data, writeByteOrderMark, onError, sourceFiles);\n },\n\n readFile: (fileName: string) => {\n addDependee(fileName);\n\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n cache.content = compilerHost.readFile.call(this, fileName);\n }\n return cache.content;\n },\n\n // ng specific\n moduleNameToFileName: (moduleName: string, containingFile: string) => {\n const { resolvedModule } = ts.resolveModuleName(\n moduleName,\n ensureUnixPath(containingFile),\n compilerOptions,\n compilerHost,\n moduleResolutionCache,\n );\n\n return resolvedModule && resolvedModule.resolvedFileName;\n },\n\n resolveModuleNames: (moduleNames: string[], containingFile: string) => {\n return moduleNames.map(moduleName => {\n const { resolvedModule } = ts.resolveModuleName(\n moduleName,\n ensureUnixPath(containingFile),\n compilerOptions,\n compilerHost,\n moduleResolutionCache,\n );\n\n return resolvedModule;\n });\n },\n\n resourceNameToFileName: (resourceName: string, containingFilePath: string) => {\n const resourcePath = path.resolve(path.dirname(containingFilePath), resourceName);\n const containingNode = getNode(containingFilePath);\n const resourceNode = getNode(resourcePath);\n containingNode.dependsOn(resourceNode);\n\n return resourcePath;\n },\n\n readResource: (fileName: string) => {\n addDependee(fileName);\n\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n if (/(html|htm|svg)$/.test(path.extname(fileName))) {\n // template\n cache.content = compilerHost.readFile.call(this, fileName);\n } else {\n // stylesheet\n try {\n cache.content = stylesheetProcessor.process(fileName);\n } catch (err) {\n error('\\n' + err.message + ` in stylesheet file ${fileName}.`);\n throw err;\n }\n }\n\n if (cache.content === undefined) {\n throw new Error(`Cannot read file ${fileName}.`);\n };\n\n cache.exists = true;\n }\n\n return cache.content;\n },\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng-packagr",
3
- "version": "12.0.0-rc.2",
3
+ "version": "12.0.2",
4
4
  "description": "Compile and package Angular libraries in Angular Package Format (APF)",
5
5
  "keywords": [
6
6
  "apf",
@@ -29,7 +29,7 @@
29
29
  "main": "./public_api.js",
30
30
  "typings": "./public_api.d.ts",
31
31
  "dependencies": {
32
- "@rollup/plugin-commonjs": "^18.0.0",
32
+ "@rollup/plugin-commonjs": "^19.0.0",
33
33
  "@rollup/plugin-json": "^4.1.0",
34
34
  "@rollup/plugin-node-resolve": "^13.0.0",
35
35
  "ajv": "^8.0.0",