ng-packagr 13.0.0 → 13.0.5
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/cli/main.js +1 -1
- package/cli/main.js.map +1 -1
- package/lib/ng-package/discover-packages.js +3 -1
- package/lib/ng-package/discover-packages.js.map +1 -1
- package/lib/ng-package/entry-point/write-package.transform.js +26 -20
- package/lib/ng-package/entry-point/write-package.transform.js.map +1 -1
- package/lib/styles/stylesheet-processor.d.ts +3 -2
- package/lib/styles/stylesheet-processor.js +14 -19
- package/lib/styles/stylesheet-processor.js.map +1 -1
- package/package.json +3 -4
package/cli/main.js
CHANGED
|
@@ -36,7 +36,7 @@ commander_1.program
|
|
|
36
36
|
.option('-p, --project [path]', "Path to the 'ng-package.json' or 'package.json' file.", parseProjectPath, DEFAULT_PROJECT_PATH)
|
|
37
37
|
.option('-c, --config [config]', 'Path to a tsconfig file.', (value) => value ? path.resolve(value) : undefined);
|
|
38
38
|
commander_1.program.on('option:version', () => {
|
|
39
|
-
void version().then(() => process.exit(0));
|
|
39
|
+
void (0, public_api_1.version)().then(() => process.exit(0));
|
|
40
40
|
});
|
|
41
41
|
commander_1.program.parse(process.argv);
|
|
42
42
|
const { config, project, watch, version } = commander_1.program.opts();
|
package/cli/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,yCAAoC;AACpC,2CAA6B;AAC7B,0CAAyC;AACzC,
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/cli/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,yCAAoC;AACpC,2CAA6B;AAC7B,0CAAyC;AACzC,8CAA0E;AAE1E,MAAM,oBAAoB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,iBAAiB,CAA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path from 'path';\nimport { error } from '../lib/utils/log';\nimport { build, execute, version as versionCommand } from '../public_api';\n\nconst DEFAULT_PROJECT_PATH = path.resolve(process.cwd(), 'ng-package.json');\n\nfunction parseProjectPath(parsed: string): string {\n return parsed || DEFAULT_PROJECT_PATH;\n}\n\nprogram\n .name('ng-packagr')\n .storeOptionsAsProperties(false)\n .option('-v, --version', 'Prints version info')\n .option('-w, --watch', 'Watch for file changes')\n .option(\n '-p, --project [path]',\n \"Path to the 'ng-package.json' or 'package.json' file.\",\n parseProjectPath,\n DEFAULT_PROJECT_PATH,\n )\n .option('-c, --config [config]', 'Path to a tsconfig file.', (value: string | undefined) =>\n value ? path.resolve(value) : undefined,\n );\n\nprogram.on('option:version', () => {\n void versionCommand().then(() => process.exit(0));\n});\n\nprogram.parse(process.argv);\n\nconst { config, project, watch, version } = program.opts();\n\nif (!version) {\n execute(build, { config, project, watch: !!watch }).catch(err => {\n error(err.message);\n process.exit(1);\n });\n}\n"]}
|
|
@@ -51,7 +51,8 @@ async function resolveUserPackage(folderPathOrFilePath, isSecondary = false) {
|
|
|
51
51
|
const fullPath = path.resolve(folderPathOrFilePath);
|
|
52
52
|
const pathStats = await (0, fs_1.stat)(fullPath);
|
|
53
53
|
const basePath = pathStats.isDirectory() ? fullPath : path.dirname(fullPath);
|
|
54
|
-
const
|
|
54
|
+
const pkgJsonPath = path.join(basePath, 'package.json');
|
|
55
|
+
const packageJson = await readConfigFile(pkgJsonPath);
|
|
55
56
|
if (!packageJson && !isSecondary) {
|
|
56
57
|
throw new Error(`Cannot discover package sources at ${folderPathOrFilePath} as 'package.json' was not found.`);
|
|
57
58
|
}
|
|
@@ -62,6 +63,7 @@ async function resolveUserPackage(folderPathOrFilePath, isSecondary = false) {
|
|
|
62
63
|
if (packageJson && packageJson['ngPackage']) {
|
|
63
64
|
// Read `ngPackage` from `package.json`
|
|
64
65
|
ngPackageJson = { ...packageJson['ngPackage'] };
|
|
66
|
+
log.warn(`Found configuration in ${pkgJsonPath}.\nConfiguring ng-packagr in "package.json" is deprecated. Use "ng-package.json" instead.`);
|
|
65
67
|
}
|
|
66
68
|
else if (pathStats.isDirectory()) {
|
|
67
69
|
ngPackageJson = await readConfigFile(path.join(basePath, 'ng-package.json'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discover-packages.js","sourceRoot":"","sources":["../../../src/lib/ng-package/discover-packages.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAkD;AAClD,2CAA6B;AAC7B,oCAAqD;AACrD,wCAA0C;AAC1C,kDAAoC;AACpC,wCAA+C;AAC/C,2DAAyD;AACzD,uCAAsC;AACtC,qCAAmD;AAWnD,KAAK,UAAU,cAAc,CAAC,QAAgB;IAC5C,IAAI,CAAC,CAAC,MAAM,IAAA,WAAM,EAAC,QAAQ,CAAC,CAAC,EAAE;QAC7B,OAAO,SAAS,CAAC;KAClB;IAED,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC5B,yDAAc,QAAQ,IAAE;KACzB;IAED,MAAM,IAAI,GAAG,MAAM,IAAA,aAAQ,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAE/C,OAAO,IAAA,oBAAS,EAAC,IAAI,EAAE,SAAS,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;GAMG;AACH,KAAK,UAAU,kBAAkB,CAAC,oBAA4B,EAAE,WAAW,GAAG,KAAK;;IACjF,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACpD,MAAM,SAAS,GAAG,MAAM,IAAA,SAAI,EAAC,QAAQ,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7E,MAAM,WAAW,GAAY,MAA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AiC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KAC3F;IAED,OAAO,IAAI,mBAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AACvD,CAAC;AAtBD,4CAsBC","sourcesContent":["import { parse as parseJson } from 'jsonc-parser';\nimport * as path from 'path';\nimport { exists, readFile, stat } from '../utils/fs';\nimport { globFiles } from '../utils/glob';\nimport * as log from '../utils/log';\nimport { ensureUnixPath } from '../utils/path';\nimport { NgEntryPoint } from './entry-point/entry-point';\nimport { NgPackage } from './package';\nimport { validateNgPackageSchema } from './schema';\n\ninterface UserPackage {\n /** Values from the `package.json` file of this user package. */\n packageJson: Record<string, any>;\n /** NgPackageConfig for this user package. */\n ngPackageJson: Record<string, any>;\n /** Absolute directory path of this user package. */\n basePath: string;\n}\n\nasync function readConfigFile(filePath: string): Promise<any> {\n if (!(await exists(filePath))) {\n return undefined;\n }\n\n if (filePath.endsWith('.js')) {\n return import(filePath);\n }\n\n const data = await readFile(filePath, 'utf-8');\n\n return parseJson(data, undefined, { allowTrailingComma: true });\n}\n\n/**\n * Resolves a user's package by testing for 'package.json', 'ng-package.json', or 'ng-package.js'.\n *\n * @param folderPathOrFilePath A path pointing either to a file or a directory\n * @param isSecondary A boolean determining if this is a secondary package\n * @return The user's package\n */\nasync function resolveUserPackage(folderPathOrFilePath: string, isSecondary = false): Promise<UserPackage | undefined> {\n const fullPath = path.resolve(folderPathOrFilePath);\n const pathStats = await stat(fullPath);\n const basePath = pathStats.isDirectory() ? fullPath : path.dirname(fullPath);\n const packageJson: unknown = await readConfigFile(path.join(basePath, 'package.json'));\n\n if (!packageJson && !isSecondary) {\n throw new Error(`Cannot discover package sources at ${folderPathOrFilePath} as 'package.json' was not found.`);\n }\n\n if (packageJson && typeof packageJson !== 'object') {\n throw new Error(`Invalid 'package.json' at ${folderPathOrFilePath}.`);\n }\n\n let ngPackageJson: unknown;\n if (packageJson && packageJson['ngPackage']) {\n // Read `ngPackage` from `package.json`\n ngPackageJson = { ...packageJson['ngPackage'] };\n } else if (pathStats.isDirectory()) {\n ngPackageJson = await readConfigFile(path.join(basePath, 'ng-package.json'));\n if (!ngPackageJson) {\n ngPackageJson = await readConfigFile(path.join(basePath, 'ng-package.js'));\n }\n } else {\n ngPackageJson = await readConfigFile(fullPath);\n }\n\n if (ngPackageJson) {\n ngPackageJson = ngPackageJson['default'] ?? ngPackageJson;\n\n validateNgPackageSchema(ngPackageJson);\n\n return {\n basePath,\n packageJson: packageJson || {},\n ngPackageJson,\n };\n }\n\n if (pathStats.isDirectory()) {\n // return even if it's undefined and use defaults when it's not a file\n return undefined;\n }\n\n if (pathStats.isFile()) {\n // a project file was specified but was in valid\n if (path.basename(folderPathOrFilePath) === 'package.json') {\n throw new Error(`Cannot read a package from 'package.json' without 'ngPackage' property.`);\n }\n\n throw new Error(`Trying to read a package from unsupported file extension. Path: ${folderPathOrFilePath}`);\n }\n\n throw new Error(`Cannot discover package sources at ${folderPathOrFilePath}`);\n}\n\n/**\n * Scans `directoryPath` and sub-folders, looking for `package.json` files.\n * Similar to `find ${directoryPath} --name package.json --exec dirname {}`.\n *\n * @param directoryPath Path pointing to a directory\n * @param excludeFolder A sub-folder of `directoryPath` that is excluded from search results.\n */\nasync function findSecondaryPackagesPaths(directoryPath: string, excludeFolder: string): Promise<string[]> {\n const ignore = [\n '**/node_modules/**',\n '**/.git/**',\n `${path.resolve(directoryPath, excludeFolder)}/**`,\n `${directoryPath}/package.json`,\n `${directoryPath}/ng-package.json`,\n ];\n\n const filePaths = await globFiles(`${directoryPath}/**/{package,ng-package}.json`, {\n ignore,\n nodir: true,\n cwd: directoryPath,\n });\n\n return filePaths.map(path.dirname);\n}\n\n/**\n * Reads a secondary entry point from it's package file.\n *\n * @param primary The primary entry point.\n * @param userPackage The user package for the secondary entry point.\n */\nfunction secondaryEntryPoint(primary: NgEntryPoint, userPackage: UserPackage): NgEntryPoint {\n const { packageJson, ngPackageJson, basePath } = userPackage;\n if (path.resolve(basePath) === path.resolve(primary.basePath)) {\n log.error(`Cannot read secondary entry point. It's already a primary entry point. Path: ${basePath}`);\n throw new Error(`Secondary entry point is already a primary.`);\n }\n\n const relativeSourcePath = path.relative(primary.basePath, basePath);\n const secondaryModuleId = ensureUnixPath(`${primary.moduleId}/${relativeSourcePath}`);\n\n return new NgEntryPoint(packageJson, ngPackageJson, basePath, {\n moduleId: secondaryModuleId,\n primaryDestinationPath: primary.destinationPath,\n destinationPath: path.join(primary.destinationPath, relativeSourcePath),\n });\n}\n\nexport async function discoverPackages({ project }: { project: string }): Promise<NgPackage> {\n project = path.isAbsolute(project) ? project : path.resolve(project);\n\n const { packageJson, ngPackageJson, basePath } = await resolveUserPackage(project);\n const primary = new NgEntryPoint(packageJson, ngPackageJson, basePath);\n log.debug(`Found primary entry point: ${primary.moduleId}`);\n\n const folderPaths = await findSecondaryPackagesPaths(basePath, primary.$get('dest'));\n const secondaries: NgEntryPoint[] = [];\n\n for (const folderPath of folderPaths) {\n const secondaryPackage = await resolveUserPackage(folderPath, true);\n if (secondaryPackage) {\n secondaries.push(secondaryEntryPoint(primary, secondaryPackage));\n }\n }\n\n if (secondaries.length > 0) {\n log.debug(`Found secondary entry points: ${secondaries.map(e => e.moduleId).join(', ')}`);\n }\n\n return new NgPackage(basePath, primary, secondaries);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"discover-packages.js","sourceRoot":"","sources":["../../../src/lib/ng-package/discover-packages.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAkD;AAClD,2CAA6B;AAC7B,oCAAqD;AACrD,wCAA0C;AAC1C,kDAAoC;AACpC,wCAA+C;AAC/C,2DAAyD;AACzD,uCAAsC;AACtC,qCAAmD;AAWnD,KAAK,UAAU,cAAc,CAAC,QAAgB;IAC5C,IAAI,CAAC,CAAC,MAAM,IAAA,WAA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AC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAErE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACnF,MAAM,OAAO,GAAG,IAAI,0BAAY,CAAC,WAAW,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;IACvE,GAAG,CAAC,KAAK,CAAC,8BAA8B,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE5D,MAAM,WAAW,GAAG,MAAM,0BAA0B,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACrF,MAAM,WAAW,GAAmB,EAAE,CAAC;IAEvC,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,MAAM,gBAAgB,GAAG,MAAM,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACpE,IAAI,gBAAgB,EAAE;YACpB,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC;SAClE;KACF;IAED,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;QAC1B,GAAG,CAAC,KAAK,CAAC,iCAAiC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KAC3F;IAED,OAAO,IAAI,mBAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AACvD,CAAC;AAtBD,4CAsBC","sourcesContent":["import { parse as parseJson } from 'jsonc-parser';\nimport * as path from 'path';\nimport { exists, readFile, stat } from '../utils/fs';\nimport { globFiles } from '../utils/glob';\nimport * as log from '../utils/log';\nimport { ensureUnixPath } from '../utils/path';\nimport { NgEntryPoint } from './entry-point/entry-point';\nimport { NgPackage } from './package';\nimport { validateNgPackageSchema } from './schema';\n\ninterface UserPackage {\n /** Values from the `package.json` file of this user package. */\n packageJson: Record<string, any>;\n /** NgPackageConfig for this user package. */\n ngPackageJson: Record<string, any>;\n /** Absolute directory path of this user package. */\n basePath: string;\n}\n\nasync function readConfigFile(filePath: string): Promise<any> {\n if (!(await exists(filePath))) {\n return undefined;\n }\n\n if (filePath.endsWith('.js')) {\n return import(filePath);\n }\n\n const data = await readFile(filePath, 'utf-8');\n\n return parseJson(data, undefined, { allowTrailingComma: true });\n}\n\n/**\n * Resolves a user's package by testing for 'package.json', 'ng-package.json', or 'ng-package.js'.\n *\n * @param folderPathOrFilePath A path pointing either to a file or a directory\n * @param isSecondary A boolean determining if this is a secondary package\n * @return The user's package\n */\nasync function resolveUserPackage(folderPathOrFilePath: string, isSecondary = false): Promise<UserPackage | undefined> {\n const fullPath = path.resolve(folderPathOrFilePath);\n const pathStats = await stat(fullPath);\n const basePath = pathStats.isDirectory() ? fullPath : path.dirname(fullPath);\n const pkgJsonPath = path.join(basePath, 'package.json');\n const packageJson: unknown = await readConfigFile(pkgJsonPath);\n\n if (!packageJson && !isSecondary) {\n throw new Error(`Cannot discover package sources at ${folderPathOrFilePath} as 'package.json' was not found.`);\n }\n\n if (packageJson && typeof packageJson !== 'object') {\n throw new Error(`Invalid 'package.json' at ${folderPathOrFilePath}.`);\n }\n\n let ngPackageJson: unknown;\n if (packageJson && packageJson['ngPackage']) {\n // Read `ngPackage` from `package.json`\n ngPackageJson = { ...packageJson['ngPackage'] };\n log.warn(\n `Found configuration in ${pkgJsonPath}.\\nConfiguring ng-packagr in \"package.json\" is deprecated. Use \"ng-package.json\" instead.`,\n );\n } else if (pathStats.isDirectory()) {\n ngPackageJson = await readConfigFile(path.join(basePath, 'ng-package.json'));\n if (!ngPackageJson) {\n ngPackageJson = await readConfigFile(path.join(basePath, 'ng-package.js'));\n }\n } else {\n ngPackageJson = await readConfigFile(fullPath);\n }\n\n if (ngPackageJson) {\n ngPackageJson = ngPackageJson['default'] ?? ngPackageJson;\n\n validateNgPackageSchema(ngPackageJson);\n\n return {\n basePath,\n packageJson: packageJson || {},\n ngPackageJson,\n };\n }\n\n if (pathStats.isDirectory()) {\n // return even if it's undefined and use defaults when it's not a file\n return undefined;\n }\n\n if (pathStats.isFile()) {\n // a project file was specified but was in valid\n if (path.basename(folderPathOrFilePath) === 'package.json') {\n throw new Error(`Cannot read a package from 'package.json' without 'ngPackage' property.`);\n }\n\n throw new Error(`Trying to read a package from unsupported file extension. Path: ${folderPathOrFilePath}`);\n }\n\n throw new Error(`Cannot discover package sources at ${folderPathOrFilePath}`);\n}\n\n/**\n * Scans `directoryPath` and sub-folders, looking for `package.json` files.\n * Similar to `find ${directoryPath} --name package.json --exec dirname {}`.\n *\n * @param directoryPath Path pointing to a directory\n * @param excludeFolder A sub-folder of `directoryPath` that is excluded from search results.\n */\nasync function findSecondaryPackagesPaths(directoryPath: string, excludeFolder: string): Promise<string[]> {\n const ignore = [\n '**/node_modules/**',\n '**/.git/**',\n `${path.resolve(directoryPath, excludeFolder)}/**`,\n `${directoryPath}/package.json`,\n `${directoryPath}/ng-package.json`,\n ];\n\n const filePaths = await globFiles(`${directoryPath}/**/{package,ng-package}.json`, {\n ignore,\n nodir: true,\n cwd: directoryPath,\n });\n\n return filePaths.map(path.dirname);\n}\n\n/**\n * Reads a secondary entry point from it's package file.\n *\n * @param primary The primary entry point.\n * @param userPackage The user package for the secondary entry point.\n */\nfunction secondaryEntryPoint(primary: NgEntryPoint, userPackage: UserPackage): NgEntryPoint {\n const { packageJson, ngPackageJson, basePath } = userPackage;\n if (path.resolve(basePath) === path.resolve(primary.basePath)) {\n log.error(`Cannot read secondary entry point. It's already a primary entry point. Path: ${basePath}`);\n throw new Error(`Secondary entry point is already a primary.`);\n }\n\n const relativeSourcePath = path.relative(primary.basePath, basePath);\n const secondaryModuleId = ensureUnixPath(`${primary.moduleId}/${relativeSourcePath}`);\n\n return new NgEntryPoint(packageJson, ngPackageJson, basePath, {\n moduleId: secondaryModuleId,\n primaryDestinationPath: primary.destinationPath,\n destinationPath: path.join(primary.destinationPath, relativeSourcePath),\n });\n}\n\nexport async function discoverPackages({ project }: { project: string }): Promise<NgPackage> {\n project = path.isAbsolute(project) ? project : path.resolve(project);\n\n const { packageJson, ngPackageJson, basePath } = await resolveUserPackage(project);\n const primary = new NgEntryPoint(packageJson, ngPackageJson, basePath);\n log.debug(`Found primary entry point: ${primary.moduleId}`);\n\n const folderPaths = await findSecondaryPackagesPaths(basePath, primary.$get('dest'));\n const secondaries: NgEntryPoint[] = [];\n\n for (const folderPath of folderPaths) {\n const secondaryPackage = await resolveUserPackage(folderPath, true);\n if (secondaryPackage) {\n secondaries.push(secondaryEntryPoint(primary, secondaryPackage));\n }\n }\n\n if (secondaries.length > 0) {\n log.debug(`Found secondary entry points: ${secondaries.map(e => e.moduleId).join(', ')}`);\n }\n\n return new NgPackage(basePath, primary, secondaries);\n}\n"]}
|
|
@@ -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
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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
|
-
|
|
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,CA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{ 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,CA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C,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,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
|
|
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
|
-
|
|
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;
|
|
@@ -24,7 +24,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.StylesheetProcessor = exports.InlineStyleLanguage = exports.CssUrl = void 0;
|
|
26
26
|
const browserslist_1 = __importDefault(require("browserslist"));
|
|
27
|
-
const find_parent_dir_1 = require("find-parent-dir");
|
|
28
27
|
const fs_1 = require("fs");
|
|
29
28
|
const path_1 = require("path");
|
|
30
29
|
const postcss_1 = __importDefault(require("postcss"));
|
|
@@ -46,10 +45,10 @@ var InlineStyleLanguage;
|
|
|
46
45
|
InlineStyleLanguage["less"] = "less";
|
|
47
46
|
})(InlineStyleLanguage = exports.InlineStyleLanguage || (exports.InlineStyleLanguage = {}));
|
|
48
47
|
class StylesheetProcessor {
|
|
49
|
-
constructor(basePath, cssUrl,
|
|
48
|
+
constructor(basePath, cssUrl, includePaths, cacheDirectory) {
|
|
50
49
|
this.basePath = basePath;
|
|
51
50
|
this.cssUrl = cssUrl;
|
|
52
|
-
this.
|
|
51
|
+
this.includePaths = includePaths;
|
|
53
52
|
this.cacheDirectory = cacheDirectory;
|
|
54
53
|
this.esbuild = new esbuild_executor_1.EsbuildExecutor();
|
|
55
54
|
log.debug(`determine browserslist for ${this.basePath}`);
|
|
@@ -65,6 +64,17 @@ class StylesheetProcessor {
|
|
|
65
64
|
'last 2 iOS major versions',
|
|
66
65
|
'Firefox ESR',
|
|
67
66
|
];
|
|
67
|
+
this.styleIncludePaths = [...this.includePaths];
|
|
68
|
+
let prevDir = null;
|
|
69
|
+
let currentDir = this.basePath;
|
|
70
|
+
while (currentDir !== prevDir) {
|
|
71
|
+
const p = (0, path_1.join)(currentDir, 'node_modules');
|
|
72
|
+
if ((0, fs_1.existsSync)(p)) {
|
|
73
|
+
this.styleIncludePaths.push(p);
|
|
74
|
+
}
|
|
75
|
+
prevDir = currentDir;
|
|
76
|
+
currentDir = (0, path_1.dirname)(prevDir);
|
|
77
|
+
}
|
|
68
78
|
this.browserslistData = (0, browserslist_1.default)(undefined, { path: this.basePath });
|
|
69
79
|
this.targets = transformSupportedBrowsersToTargets(this.browserslistData);
|
|
70
80
|
this.postCssProcessor = this.createPostCssPlugins();
|
|
@@ -207,24 +217,9 @@ function customSassImporter(url, prev) {
|
|
|
207
217
|
if (url[0] !== '~') {
|
|
208
218
|
return undefined;
|
|
209
219
|
}
|
|
210
|
-
const result = resolveImport(url.substr(1), prev);
|
|
211
|
-
if (!result) {
|
|
212
|
-
return undefined;
|
|
213
|
-
}
|
|
214
220
|
return {
|
|
215
|
-
file:
|
|
221
|
+
file: url.substr(1),
|
|
216
222
|
prev,
|
|
217
223
|
};
|
|
218
224
|
}
|
|
219
|
-
function resolveImport(target, basePath) {
|
|
220
|
-
const root = (0, find_parent_dir_1.sync)(basePath, 'node_modules');
|
|
221
|
-
if (!root) {
|
|
222
|
-
return undefined;
|
|
223
|
-
}
|
|
224
|
-
const filePath = (0, path_1.resolve)(root, 'node_modules', target);
|
|
225
|
-
if ((0, fs_1.existsSync)(filePath) || (0, fs_1.existsSync)((0, path_1.dirname)(filePath))) {
|
|
226
|
-
return filePath;
|
|
227
|
-
}
|
|
228
|
-
return resolveImport(target, (0, path_1.dirname)(root));
|
|
229
|
-
}
|
|
230
225
|
//# sourceMappingURL=stylesheet-processor.js.map
|
|
@@ -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,8BAA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AAI,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, 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,2BAAgC;AAChC,+BAA8C;AAC9C,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,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OAAO,CAAC,CAAC;SACzC;KACF;IAED,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC;AAED,SAAS,kBAAkB,CAAC,GAAW,EAAE,IAAY;IACnD,qEAAqE;IACrE,gDAAgD;IAChD,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QAClB,OAAO,SAAS,CAAC;KAClB;IAED,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACnB,IAAI;KACL,CAAC;AACJ,CAAC","sourcesContent":["import browserslist from 'browserslist';\nimport { existsSync } from 'fs';\nimport { dirname, extname, join } 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 this.styleIncludePaths = [...this.includePaths];\n let prevDir = null;\n let currentDir = this.basePath;\n\n while (currentDir !== prevDir) {\n const p = join(currentDir, 'node_modules');\n if (existsSync(p)) {\n this.styleIncludePaths.push(p);\n }\n\n prevDir = currentDir;\n currentDir = dirname(prevDir);\n }\n\n this.browserslistData = browserslist(undefined, { path: this.basePath });\n this.targets = transformSupportedBrowsersToTargets(this.browserslistData);\n this.postCssProcessor = this.createPostCssPlugins();\n }\n\n async process({ filePath, content }: { filePath: string; content: string }): Promise<string> {\n let key: string | undefined;\n\n if (!content.includes('@import') && !content.includes('@use') && this.cacheDirectory) {\n // No transitive deps, we can cache more aggressively.\n key = await generateKey(content, ...this.browserslistData);\n const result = await readCacheEntry(this.cacheDirectory, key);\n if (result) {\n result.warnings.forEach(msg => log.warn(msg));\n\n return result.css;\n }\n }\n\n // Render pre-processor language (sass, styl, less)\n const renderedCss = await this.renderCss(filePath, content);\n\n // We cannot cache CSS re-rendering phase, because a transitive dependency via (@import) can case different CSS output.\n // Example a change in a mixin or SCSS variable.\n if (!key) {\n key = await generateKey(renderedCss, ...this.browserslistData);\n }\n\n if (this.cacheDirectory) {\n const cachedResult = await readCacheEntry(this.cacheDirectory, key);\n if (cachedResult) {\n cachedResult.warnings.forEach(msg => log.warn(msg));\n\n return cachedResult.css;\n }\n }\n // Render postcss (autoprefixing and friends)\n const result = await this.postCssProcessor.process(renderedCss, {\n from: filePath,\n to: filePath.replace(extname(filePath), '.css'),\n });\n\n const warnings = result.warnings().map(w => w.toString());\n const { code, warnings: esBuildWarnings } = await this.esbuild.transform(result.css, {\n loader: 'css',\n minify: true,\n target: this.targets,\n sourcefile: filePath,\n });\n\n if (esBuildWarnings.length > 0) {\n warnings.push(...(await this.esbuild.formatMessages(esBuildWarnings, { kind: 'warning' })));\n }\n\n if (this.cacheDirectory) {\n await saveCacheEntry(\n this.cacheDirectory,\n key,\n JSON.stringify({\n css: code,\n warnings,\n }),\n );\n }\n warnings.forEach(msg => log.warn(msg));\n\n return code;\n }\n\n private createPostCssPlugins(): ReturnType<typeof postcss> {\n const postCssPlugins = [];\n 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 return {\n file: url.substr(1),\n prev,\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ng-packagr",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.5",
|
|
4
4
|
"description": "Compile and package Angular libraries in Angular Package Format (APF)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apf",
|
|
@@ -40,14 +40,13 @@
|
|
|
40
40
|
"dependency-graph": "^0.11.0",
|
|
41
41
|
"esbuild-wasm": "^0.13.0",
|
|
42
42
|
"find-cache-dir": "^3.3.1",
|
|
43
|
-
"find-parent-dir": "^0.3.1",
|
|
44
43
|
"glob": "^7.1.6",
|
|
45
44
|
"injection-js": "^2.4.0",
|
|
46
45
|
"jsonc-parser": "^3.0.0",
|
|
47
46
|
"less": "^4.1.0",
|
|
48
47
|
"ora": "^5.1.0",
|
|
49
48
|
"postcss": "^8.2.4",
|
|
50
|
-
"postcss-preset-env": "^
|
|
49
|
+
"postcss-preset-env": "^7.0.0",
|
|
51
50
|
"postcss-url": "^10.1.1",
|
|
52
51
|
"rollup": "^2.45.1",
|
|
53
52
|
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
@@ -59,7 +58,7 @@
|
|
|
59
58
|
"esbuild": "^0.13.0"
|
|
60
59
|
},
|
|
61
60
|
"peerDependencies": {
|
|
62
|
-
"@angular/compiler-cli": "^13.0.0-next
|
|
61
|
+
"@angular/compiler-cli": "^13.0.0 || ^13.1.0-next",
|
|
63
62
|
"tslib": "^2.3.0",
|
|
64
63
|
"typescript": "~4.4.0"
|
|
65
64
|
}
|