ng-packagr 19.2.0 → 20.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ng-package/discover-packages.js +3 -11
- package/lib/ng-package/discover-packages.js.map +1 -1
- package/lib/ng-package/entry-point/write-package.transform.js +7 -24
- package/lib/ng-package/entry-point/write-package.transform.js.map +1 -1
- package/lib/styles/stylesheets/stylesheet-plugin-factory.js +2 -2
- package/lib/styles/stylesheets/stylesheet-plugin-factory.js.map +1 -1
- package/package.json +3 -3
- package/lib/utils/array.d.ts +0 -2
- package/lib/utils/array.js +0 -11
- package/lib/utils/array.js.map +0 -1
- package/lib/utils/glob.d.ts +0 -2
- package/lib/utils/glob.js +0 -13
- package/lib/utils/glob.js.map +0 -1
|
@@ -36,8 +36,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.discoverPackages = discoverPackages;
|
|
37
37
|
const jsonc_parser_1 = require("jsonc-parser");
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
|
+
const tinyglobby_1 = require("tinyglobby");
|
|
39
40
|
const fs_1 = require("../utils/fs");
|
|
40
|
-
const glob_1 = require("../utils/glob");
|
|
41
41
|
const log = __importStar(require("../utils/log"));
|
|
42
42
|
const path_1 = require("../utils/path");
|
|
43
43
|
const entry_point_1 = require("./entry-point/entry-point");
|
|
@@ -100,11 +100,7 @@ async function resolveUserPackage(folderPathOrFilePath, isSecondary = false) {
|
|
|
100
100
|
throw new Error(`Invalid 'package.json' at ${folderPathOrFilePath}.`);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
|
-
return {
|
|
104
|
-
basePath,
|
|
105
|
-
packageJson,
|
|
106
|
-
ngPackageJson,
|
|
107
|
-
};
|
|
103
|
+
return { basePath, packageJson, ngPackageJson };
|
|
108
104
|
}
|
|
109
105
|
if (pathStats.isDirectory()) {
|
|
110
106
|
// return even if it's undefined and use defaults when it's not a file
|
|
@@ -124,11 +120,7 @@ async function resolveUserPackage(folderPathOrFilePath, isSecondary = false) {
|
|
|
124
120
|
*/
|
|
125
121
|
async function findSecondaryPackagesPaths(directoryPath, excludeFolder) {
|
|
126
122
|
const ignore = ['**/node_modules/**', '**/.git/**', `${excludeFolder}/**`, 'ng-package.json'];
|
|
127
|
-
const filePaths = await (0,
|
|
128
|
-
ignore,
|
|
129
|
-
onlyFiles: true,
|
|
130
|
-
cwd: directoryPath,
|
|
131
|
-
});
|
|
123
|
+
const filePaths = await (0, tinyglobby_1.glob)(`**/ng-package.json`, { ignore, onlyFiles: true, cwd: directoryPath });
|
|
132
124
|
return filePaths.map(subpath => path.dirname(path.join(directoryPath, subpath)));
|
|
133
125
|
}
|
|
134
126
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discover-packages.js","sourceRoot":"","sources":["../../../src/lib/ng-package/discover-packages.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+IA,4CAsBC;AArKD,+CAAkD;AAClD,2CAA6B;AAC7B,oCAAqD;AACrD,wCAA0C;AAC1C,kDAAoC;AACpC,wCAA+C;AAC/C,2DAAyD;AACzD,uCAAsC;AACtC,qCAAsF;AAWtF,KAAK,UAAU,cAAc,CAAC,QAAgB;IAC5C,IAAI,CAAC,CAAC,MAAM,IAAA,WAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QAC9B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,0BAAc,QAAQ,wCAAE;IAC1B,CAAC;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,KA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,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,CAAC;QACrC,MAAM,gBAAgB,GAAG,MAAM,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACpE,IAAI,gBAAgB,EAAE,CAAC;YACrB,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,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;IAC5F,CAAC;IAED,OAAO,IAAI,mBAAS,CAAC,IAAA,qBAAc,EAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AACvE,CAAC","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 { validateNgPackageEntryPointSchema, 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 '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\n let ngPackageJson: unknown;\n 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 try {\n if (isSecondary) {\n validateNgPackageEntryPointSchema(ngPackageJson);\n } else {\n validateNgPackageSchema(ngPackageJson);\n }\n } catch (e) {\n log.error(`An error has occurred while validating config at ${folderPathOrFilePath}`);\n throw e;\n }\n\n let packageJson: {} = {};\n if (!isSecondary) {\n const pkgJsonPath = path.join(basePath, 'package.json');\n packageJson = await readConfigFile(pkgJsonPath);\n\n if (!packageJson) {\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\n return {\n basePath,\n 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 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 `ng-package` files.\n * Similar to `find ${directoryPath} --name ng-package --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 = ['**/node_modules/**', '**/.git/**', `${excludeFolder}/**`, 'ng-package.json'];\n\n const filePaths = await globFiles(`**/ng-package.json`, {\n ignore,\n onlyFiles: true,\n cwd: directoryPath,\n });\n\n return filePaths.map(subpath => path.dirname(path.join(directoryPath, subpath)));\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(ensureUnixPath(basePath), primary, secondaries);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"discover-packages.js","sourceRoot":"","sources":["../../../src/lib/ng-package/discover-packages.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuIA,4CAsBC;AA7JD,+CAAkD;AAClD,2CAA6B;AAC7B,2CAAkC;AAClC,oCAAqD;AACrD,kDAAoC;AACpC,wCAA+C;AAC/C,2DAAyD;AACzD,uCAAsC;AACtC,qCAAsF;AAWtF,KAAK,UAAU,cAAc,CAAC,QAAgB;IAC5C,IAAI,CAAC,CAAC,MAAM,IAAA,WAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;QAC9B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,0BAAc,QAAQ,wCAAE;IAC1B,CAAC;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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,kBAAkB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QACpE,IAAI,gBAAgB,EAAE,CAAC;YACrB,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,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;IAC5F,CAAC;IAED,OAAO,IAAI,mBAAS,CAAC,IAAA,qBAAc,EAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import { parse as parseJson } from 'jsonc-parser';\nimport * as path from 'path';\nimport { glob } from 'tinyglobby';\nimport { exists, readFile, stat } from '../utils/fs';\nimport * as log from '../utils/log';\nimport { ensureUnixPath } from '../utils/path';\nimport { NgEntryPoint } from './entry-point/entry-point';\nimport { NgPackage } from './package';\nimport { validateNgPackageEntryPointSchema, 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 '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\n let ngPackageJson: unknown;\n 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 try {\n if (isSecondary) {\n validateNgPackageEntryPointSchema(ngPackageJson);\n } else {\n validateNgPackageSchema(ngPackageJson);\n }\n } catch (e) {\n log.error(`An error has occurred while validating config at ${folderPathOrFilePath}`);\n throw e;\n }\n\n let packageJson: {} = {};\n if (!isSecondary) {\n const pkgJsonPath = path.join(basePath, 'package.json');\n packageJson = await readConfigFile(pkgJsonPath);\n\n if (!packageJson) {\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\n return { basePath, packageJson, ngPackageJson };\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 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 `ng-package` files.\n * Similar to `find ${directoryPath} --name ng-package --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 = ['**/node_modules/**', '**/.git/**', `${excludeFolder}/**`, 'ng-package.json'];\n\n const filePaths = await glob(`**/ng-package.json`, { ignore, onlyFiles: true, cwd: directoryPath });\n\n return filePaths.map(subpath => path.dirname(path.join(directoryPath, subpath)));\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(ensureUnixPath(basePath), primary, secondaries);\n}\n"]}
|
|
@@ -39,20 +39,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.writePackageTransform = void 0;
|
|
40
40
|
const ora_1 = __importDefault(require("ora"));
|
|
41
41
|
const path = __importStar(require("path"));
|
|
42
|
+
const tinyglobby_1 = require("tinyglobby");
|
|
42
43
|
const node_1 = require("../../graph/node");
|
|
43
44
|
const transform_1 = require("../../graph/transform");
|
|
44
45
|
const color_1 = require("../../utils/color");
|
|
45
46
|
const fs_1 = require("../../utils/fs");
|
|
46
|
-
const glob_1 = require("../../utils/glob");
|
|
47
47
|
const log = __importStar(require("../../utils/log"));
|
|
48
48
|
const path_1 = require("../../utils/path");
|
|
49
49
|
const nodes_1 = require("../nodes");
|
|
50
50
|
const writePackageTransform = (options) => (0, transform_1.transformFromPromise)(async (graph) => {
|
|
51
51
|
var _a;
|
|
52
|
-
const spinner = (0, ora_1.default)({
|
|
53
|
-
hideCursor: false,
|
|
54
|
-
discardStdin: false,
|
|
55
|
-
});
|
|
52
|
+
const spinner = (0, ora_1.default)({ hideCursor: false, discardStdin: false });
|
|
56
53
|
const entryPoint = graph.find((0, nodes_1.isEntryPointInProgress)());
|
|
57
54
|
const ngEntryPoint = entryPoint.data.entryPoint;
|
|
58
55
|
const ngPackageNode = graph.find(nodes_1.isPackage);
|
|
@@ -122,11 +119,7 @@ async function copyAssets(graph, entryPointNode, ngPackageNode) {
|
|
|
122
119
|
{ glob: 'LICENSE', input: '/', output: '/' },
|
|
123
120
|
...graph.filter(nodes_1.isEntryPoint).map(({ data }) => {
|
|
124
121
|
const subpath = data.entryPoint.destinationFiles.directory || '/';
|
|
125
|
-
return {
|
|
126
|
-
glob: 'README.md',
|
|
127
|
-
input: subpath,
|
|
128
|
-
output: subpath,
|
|
129
|
-
};
|
|
122
|
+
return { glob: 'README.md', input: subpath, output: subpath };
|
|
130
123
|
}),
|
|
131
124
|
];
|
|
132
125
|
const assets = [];
|
|
@@ -144,11 +137,7 @@ async function copyAssets(graph, entryPointNode, ngPackageNode) {
|
|
|
144
137
|
}
|
|
145
138
|
else if (isFile) {
|
|
146
139
|
// filenames are their own glob
|
|
147
|
-
asset = {
|
|
148
|
-
glob: path.basename(assetPath),
|
|
149
|
-
input: path.dirname(assetPath),
|
|
150
|
-
output: path.dirname(assetPath),
|
|
151
|
-
};
|
|
140
|
+
asset = { glob: path.basename(assetPath), input: path.dirname(assetPath), output: path.dirname(assetPath) };
|
|
152
141
|
}
|
|
153
142
|
else {
|
|
154
143
|
asset = { glob: assetPath, input: '/', output: '/' };
|
|
@@ -166,7 +155,7 @@ async function copyAssets(graph, entryPointNode, ngPackageNode) {
|
|
|
166
155
|
assets.push(asset);
|
|
167
156
|
}
|
|
168
157
|
for (const asset of assets) {
|
|
169
|
-
const filePaths = await (0,
|
|
158
|
+
const filePaths = await (0, tinyglobby_1.glob)(asset.glob, {
|
|
170
159
|
cwd: asset.input,
|
|
171
160
|
ignore: [...((_a = asset.ignore) !== null && _a !== void 0 ? _a : []), ...globsForceIgnored],
|
|
172
161
|
dot: true,
|
|
@@ -220,18 +209,12 @@ async function writePackageJson(entryPoint, pkg, additionalProperties, isWatchMo
|
|
|
220
209
|
const { peerDependencies: angularPeerDependencies = {}, dependencies: angularDependencies = {}, } = require('@angular/compiler/package.json');
|
|
221
210
|
const tsLibVersion = angularPeerDependencies.tslib || angularDependencies.tslib;
|
|
222
211
|
if (tsLibVersion) {
|
|
223
|
-
packageJson.dependencies = {
|
|
224
|
-
...packageJson.dependencies,
|
|
225
|
-
tslib: tsLibVersion,
|
|
226
|
-
};
|
|
212
|
+
packageJson.dependencies = { ...packageJson.dependencies, tslib: tsLibVersion };
|
|
227
213
|
}
|
|
228
214
|
}
|
|
229
215
|
else if ((_c = packageJson.peerDependencies) === null || _c === void 0 ? void 0 : _c.tslib) {
|
|
230
216
|
spinner.warn(color_1.colors.yellow(`'tslib' is no longer recommended to be used as a 'peerDependencies'. Moving it to 'dependencies'.`));
|
|
231
|
-
packageJson.dependencies = {
|
|
232
|
-
...(packageJson.dependencies || {}),
|
|
233
|
-
tslib: packageJson.peerDependencies.tslib,
|
|
234
|
-
};
|
|
217
|
+
packageJson.dependencies = { ...(packageJson.dependencies || {}), tslib: packageJson.peerDependencies.tslib };
|
|
235
218
|
delete packageJson.peerDependencies.tslib;
|
|
236
219
|
}
|
|
237
220
|
// Verify non-peerDependencies as they can easily lead to duplicate installs or version conflicts
|
|
@@ -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;AAG7B,2CAAwC;AACxC,qDAA6D;AAC7D,6CAA2C;AAC3C,uCAAoF;AACpF,2CAA6C;AAC7C,qDAAuC;AACvC,2CAAkD;AAClD,oCAAiH;AAO1G,MAAM,qBAAqB,GAAG,CAAC,OAAyB,EAAE,EAAE,CACjE,IAAA,gCAAoB,EAAC,KAAK,EAAC,KAAK,EAAC,EAAE;;IACjC,MAAM,OAAO,GAAG,IAAA,aAAG,EAAC;QAClB,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;IACH,MAAM,UAAU,GAAmB,KAAK,CAAC,IAAI,CAAC,IAAA,8BAAsB,GAAE,CAAC,CAAC;IACxE,MAAM,YAAY,GAAiB,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;IAC9D,MAAM,aAAa,GAAgB,KAAK,CAAC,IAAI,CAAC,iBAAS,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC;IACrC,MAAM,EAAE,gBAAgB,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC;IAE7C,IAAI,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAC;QACxC,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAChC,IAAI,CAAC;YACH,MAAM,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC;QACrD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO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F,oBAAoB,CAAC,OAAO,EAAE;YAC5B,KAAK,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,YAAY,CAAC;YAC9D,OAAO,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,QAAQ,CAAC;SAC7D,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB;IAC3B,OAAO,eAAe,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AACrC,CAAC","sourcesContent":["import ora from 'ora';\nimport * as path from 'path';\nimport { AssetPattern } from '../../../ng-package.schema';\nimport { BuildGraph } from '../../graph/build-graph';\nimport { Node } from '../../graph/node';\nimport { transformFromPromise } from '../../graph/transform';\nimport { colors } from '../../utils/color';\nimport { copyFile, exists, readFile, 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\n if (!ngEntryPoint.isSecondaryEntryPoint) {\n spinner.start('Copying assets');\n try {\n await copyAssets(graph, entryPoint, ngPackageNode);\n } catch (error) {\n spinner.fail();\n throw error;\n }\n spinner.succeed();\n }\n\n // 6. WRITE PACKAGE.JSON\n const relativeUnixFromDestPath = (filePath: string) =>\n ensureUnixPath(path.relative(ngEntryPoint.destinationPath, filePath));\n\n if (!ngEntryPoint.isSecondaryEntryPoint) {\n try {\n spinner.start('Writing package manifest');\n if (!options.watch) {\n const primary = ngPackageNode.data.primary;\n await writeFile(\n path.join(primary.destinationPath, '.npmignore'),\n `# Nested package.json's are only needed for development.\\n**/package.json`,\n );\n }\n\n const { compilationMode } = entryPoint.data.tsConfig.options;\n\n await writePackageJson(\n ngEntryPoint,\n ngPackage,\n {\n module: relativeUnixFromDestPath(destinationFiles.fesm2022),\n typings: relativeUnixFromDestPath(destinationFiles.declarations),\n exports: 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 } else if (ngEntryPoint.isSecondaryEntryPoint) {\n if (options.watch) {\n // Update the watch version of the primary entry point `package.json` file.\n // this is needed because of Webpack's 5 `cachemanagedpaths`\n // https://github.com/ng-packagr/ng-packagr/issues/2069\n const primary = ngPackageNode.data.primary;\n const packageJsonPath = path.join(primary.destinationPath, 'package.json');\n\n if (await exists(packageJsonPath)) {\n const packageJson = JSON.parse(await readFile(packageJsonPath, { encoding: 'utf8' }));\n packageJson.version = generateWatchVersion();\n await writeFile(\n path.join(primary.destinationPath, 'package.json'),\n JSON.stringify(packageJson, undefined, 2),\n );\n }\n }\n\n // Write a package.json in each secondary entry-point\n // This is need for esbuild to secondary entry-points in dist correctly.\n await writeFile(\n path.join(ngEntryPoint.destinationPath, 'package.json'),\n JSON.stringify({ module: relativeUnixFromDestPath(destinationFiles.fesm2022) }, undefined, 2),\n );\n }\n\n spinner.succeed(`Built ${ngEntryPoint.moduleId}`);\n\n return graph;\n });\n\ntype AssetEntry = Exclude<AssetPattern, string>;\n\nasync function copyAssets(\n graph: BuildGraph,\n entryPointNode: EntryPointNode,\n ngPackageNode: PackageNode,\n): Promise<void> {\n const ngPackage = ngPackageNode.data;\n\n const globsForceIgnored: string[] = ['.gitkeep', '**/.DS_Store', '**/Thumbs.db', `${ngPackage.dest}/**`];\n const defaultAssets: AssetEntry[] = [\n { glob: 'LICENSE', input: '/', output: '/' },\n ...graph.filter(isEntryPoint).map(({ data }) => {\n const subpath = data.entryPoint.destinationFiles.directory || '/';\n\n return {\n glob: 'README.md',\n input: subpath,\n output: subpath,\n };\n }),\n ];\n\n const assets: AssetEntry[] = [];\n\n for (const assetPath of [...ngPackage.assets, ...defaultAssets]) {\n let asset: AssetEntry;\n if (typeof assetPath === 'object') {\n asset = { ...assetPath };\n } else {\n const [isDir, isFile] = await stat(path.join(ngPackage.src, assetPath))\n .then(stats => [stats.isDirectory(), stats.isFile()])\n .catch(() => [false, false]);\n if (isDir) {\n asset = { glob: '**/*', input: assetPath, output: assetPath };\n } else if (isFile) {\n // filenames are their own glob\n asset = {\n glob: path.basename(assetPath),\n input: path.dirname(assetPath),\n output: path.dirname(assetPath),\n };\n } else {\n asset = { glob: assetPath, input: '/', output: '/' };\n }\n }\n\n asset.input = path.join(ngPackage.src, asset.input);\n asset.output = path.join(ngPackage.dest, asset.output);\n\n const isAncestorPath = (target: string, datum: string) => path.relative(datum, target).startsWith('..');\n if (isAncestorPath(asset.input, ngPackage.src)) {\n throw new Error('Cannot read assets from a location outside of the project root.');\n }\n if (isAncestorPath(asset.output, ngPackage.dest)) {\n throw new Error('Cannot write assets to a location outside of the output path.');\n }\n\n assets.push(asset);\n }\n\n for (const asset of assets) {\n const filePaths = await globFiles(asset.glob, {\n cwd: asset.input,\n ignore: [...(asset.ignore ?? []), ...globsForceIgnored],\n dot: true,\n onlyFiles: true,\n followSymbolicLinks: asset.followSymlinks,\n });\n for (const filePath of filePaths) {\n const fileSrcFullPath = path.join(asset.input, filePath);\n const fileDestFullPath = path.join(asset.output, filePath);\n const nodeUri = fileUrl(ensureUnixPath(fileSrcFullPath));\n let node = graph.get(nodeUri);\n if (!node) {\n node = new Node(nodeUri);\n graph.put(node);\n }\n entryPointNode.dependsOn(node);\n await copyFile(fileSrcFullPath, fileDestFullPath);\n }\n }\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 (isWatchMode) {\n // Needed because of Webpack's 5 `cachemanagedpaths`\n // https://github.com/angular/angular-cli/issues/20962\n packageJson.version = generateWatchVersion();\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 // 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 (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 types?: 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 ? JSON.parse(JSON.stringify(packageJson.exports)) : {};\n\n const insertMappingOrError = (subpath: string, mapping: ConditionalExport) => {\n exports[subpath] ??= {};\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)) {\n if (subpathExport[conditionName] !== undefined) {\n log.warn(\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 default: relativeUnixFromDestPath(destinationFiles.fesm2022),\n });\n }\n\n return exports;\n}\n\n/**\n * Generates a new version for the package `package.json` when runing in watch mode.\n */\nfunction generateWatchVersion() {\n return `0.0.0-watch+${Date.now()}`;\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;AAC7B,2CAAkC;AAGlC,2CAAwC;AACxC,qDAA6D;AAC7D,6CAA2C;AAC3C,uCAAoF;AACpF,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,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;IAChE,MAAM,UAAU,GAAmB,KAAK,CAAC,IAAI,CAAC,IAAA,8BAAsB,GAAE,CAAC,CAAC;IACxE,MAAM,YAAY,GAAiB,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC;IAC9D,MAAM,aAAa,GAAgB,KAAK,CAAC,IAAI,CAAC,iBAAS,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC;IACrC,MAAM,EAAE,gBAAgB,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC;IAE7C,IAAI,CAAC,YAAY,CAAC,qBAAqB,EAAE,CAAC;QACxC,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAChC,IAAI,CAAC;YACH,MAAM,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,aAAa,CAA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,SAAS,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QAEhF,oBAAoB,CAAC,OAAO,EAAE;YAC5B,KAAK,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,YAAY,CAAC;YAC9D,OAAO,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,QAAQ,CAAC;SAC7D,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB;IAC3B,OAAO,eAAe,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AACrC,CAAC","sourcesContent":["import ora from 'ora';\nimport * as path from 'path';\nimport { glob } from 'tinyglobby';\nimport { AssetPattern } from '../../../ng-package.schema';\nimport { BuildGraph } from '../../graph/build-graph';\nimport { Node } from '../../graph/node';\nimport { transformFromPromise } from '../../graph/transform';\nimport { colors } from '../../utils/color';\nimport { copyFile, exists, readFile, rmdir, stat, writeFile } from '../../utils/fs';\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({ hideCursor: false, discardStdin: false });\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\n if (!ngEntryPoint.isSecondaryEntryPoint) {\n spinner.start('Copying assets');\n try {\n await copyAssets(graph, entryPoint, ngPackageNode);\n } catch (error) {\n spinner.fail();\n throw error;\n }\n spinner.succeed();\n }\n\n // 6. WRITE PACKAGE.JSON\n const relativeUnixFromDestPath = (filePath: string) =>\n ensureUnixPath(path.relative(ngEntryPoint.destinationPath, filePath));\n\n if (!ngEntryPoint.isSecondaryEntryPoint) {\n try {\n spinner.start('Writing package manifest');\n if (!options.watch) {\n const primary = ngPackageNode.data.primary;\n await writeFile(\n path.join(primary.destinationPath, '.npmignore'),\n `# Nested package.json's are only needed for development.\\n**/package.json`,\n );\n }\n\n const { compilationMode } = entryPoint.data.tsConfig.options;\n\n await writePackageJson(\n ngEntryPoint,\n ngPackage,\n {\n module: relativeUnixFromDestPath(destinationFiles.fesm2022),\n typings: relativeUnixFromDestPath(destinationFiles.declarations),\n exports: 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 } else if (ngEntryPoint.isSecondaryEntryPoint) {\n if (options.watch) {\n // Update the watch version of the primary entry point `package.json` file.\n // this is needed because of Webpack's 5 `cachemanagedpaths`\n // https://github.com/ng-packagr/ng-packagr/issues/2069\n const primary = ngPackageNode.data.primary;\n const packageJsonPath = path.join(primary.destinationPath, 'package.json');\n\n if (await exists(packageJsonPath)) {\n const packageJson = JSON.parse(await readFile(packageJsonPath, { encoding: 'utf8' }));\n packageJson.version = generateWatchVersion();\n await writeFile(\n path.join(primary.destinationPath, 'package.json'),\n JSON.stringify(packageJson, undefined, 2),\n );\n }\n }\n\n // Write a package.json in each secondary entry-point\n // This is need for esbuild to secondary entry-points in dist correctly.\n await writeFile(\n path.join(ngEntryPoint.destinationPath, 'package.json'),\n JSON.stringify({ module: relativeUnixFromDestPath(destinationFiles.fesm2022) }, undefined, 2),\n );\n }\n\n spinner.succeed(`Built ${ngEntryPoint.moduleId}`);\n\n return graph;\n });\n\ntype AssetEntry = Exclude<AssetPattern, string>;\n\nasync function copyAssets(\n graph: BuildGraph,\n entryPointNode: EntryPointNode,\n ngPackageNode: PackageNode,\n): Promise<void> {\n const ngPackage = ngPackageNode.data;\n\n const globsForceIgnored: string[] = ['.gitkeep', '**/.DS_Store', '**/Thumbs.db', `${ngPackage.dest}/**`];\n const defaultAssets: AssetEntry[] = [\n { glob: 'LICENSE', input: '/', output: '/' },\n ...graph.filter(isEntryPoint).map(({ data }) => {\n const subpath = data.entryPoint.destinationFiles.directory || '/';\n\n return { glob: 'README.md', input: subpath, output: subpath };\n }),\n ];\n\n const assets: AssetEntry[] = [];\n\n for (const assetPath of [...ngPackage.assets, ...defaultAssets]) {\n let asset: AssetEntry;\n if (typeof assetPath === 'object') {\n asset = { ...assetPath };\n } else {\n const [isDir, isFile] = await stat(path.join(ngPackage.src, assetPath))\n .then(stats => [stats.isDirectory(), stats.isFile()])\n .catch(() => [false, false]);\n if (isDir) {\n asset = { glob: '**/*', input: assetPath, output: assetPath };\n } else if (isFile) {\n // filenames are their own glob\n asset = { glob: path.basename(assetPath), input: path.dirname(assetPath), output: path.dirname(assetPath) };\n } else {\n asset = { glob: assetPath, input: '/', output: '/' };\n }\n }\n\n asset.input = path.join(ngPackage.src, asset.input);\n asset.output = path.join(ngPackage.dest, asset.output);\n\n const isAncestorPath = (target: string, datum: string) => path.relative(datum, target).startsWith('..');\n if (isAncestorPath(asset.input, ngPackage.src)) {\n throw new Error('Cannot read assets from a location outside of the project root.');\n }\n if (isAncestorPath(asset.output, ngPackage.dest)) {\n throw new Error('Cannot write assets to a location outside of the output path.');\n }\n\n assets.push(asset);\n }\n\n for (const asset of assets) {\n const filePaths = await glob(asset.glob, {\n cwd: asset.input,\n ignore: [...(asset.ignore ?? []), ...globsForceIgnored],\n dot: true,\n onlyFiles: true,\n followSymbolicLinks: asset.followSymlinks,\n });\n for (const filePath of filePaths) {\n const fileSrcFullPath = path.join(asset.input, filePath);\n const fileDestFullPath = path.join(asset.output, filePath);\n const nodeUri = fileUrl(ensureUnixPath(fileSrcFullPath));\n let node = graph.get(nodeUri);\n if (!node) {\n node = new Node(nodeUri);\n graph.put(node);\n }\n entryPointNode.dependsOn(node);\n await copyFile(fileSrcFullPath, fileDestFullPath);\n }\n }\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 (isWatchMode) {\n // Needed because of Webpack's 5 `cachemanagedpaths`\n // https://github.com/angular/angular-cli/issues/20962\n packageJson.version = generateWatchVersion();\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 = { ...packageJson.dependencies, tslib: tsLibVersion };\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 = { ...(packageJson.dependencies || {}), tslib: packageJson.peerDependencies.tslib };\n\n delete packageJson.peerDependencies.tslib;\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 (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 = { types?: string; default?: string };\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 ? JSON.parse(JSON.stringify(packageJson.exports)) : {};\n\n const insertMappingOrError = (subpath: string, mapping: ConditionalExport) => {\n exports[subpath] ??= {};\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)) {\n if (subpathExport[conditionName] !== undefined) {\n log.warn(\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 default: relativeUnixFromDestPath(destinationFiles.fesm2022),\n });\n }\n\n return exports;\n}\n\n/**\n * Generates a new version for the package `package.json` when runing in watch mode.\n */\nfunction generateWatchVersion() {\n return `0.0.0-watch+${Date.now()}`;\n}\n"]}
|
|
@@ -37,10 +37,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.StylesheetPluginFactory = void 0;
|
|
40
|
-
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
41
40
|
const node_assert_1 = __importDefault(require("node:assert"));
|
|
42
41
|
const promises_1 = require("node:fs/promises");
|
|
43
42
|
const node_path_1 = require("node:path");
|
|
43
|
+
const tinyglobby_1 = require("tinyglobby");
|
|
44
44
|
const load_result_cache_1 = require("../load-result-cache");
|
|
45
45
|
/**
|
|
46
46
|
* The lazy-loaded instance of the postcss stylesheet postprocessor.
|
|
@@ -282,7 +282,7 @@ async function compileString(data, filename, postcssProcessor, options) {
|
|
|
282
282
|
typeof resultMessage['dir'] === 'string' &&
|
|
283
283
|
typeof resultMessage['glob'] === 'string') {
|
|
284
284
|
(_b = loadResult.watchFiles) !== null && _b !== void 0 ? _b : (loadResult.watchFiles = []);
|
|
285
|
-
const dependencies = await (0,
|
|
285
|
+
const dependencies = await (0, tinyglobby_1.glob)(resultMessage['glob'], {
|
|
286
286
|
absolute: true,
|
|
287
287
|
cwd: resultMessage['dir'],
|
|
288
288
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stylesheet-plugin-factory.js","sourceRoot":"","sources":["../../../../src/lib/styles/stylesheets/stylesheet-plugin-factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0DAA6B;AAC7B,8DAAiC;AACjC,+CAA4C;AAC5C,yCAAoC;AAEpC,4D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AAL,KAAK,uBAAL,KAAK,CAAG,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;yBACzE;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { OnLoadResult, Plugin, PluginBuild } from 'esbuild';\nimport glob from 'fast-glob';\nimport assert from 'node:assert';\nimport { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport type { Options } from 'sass';\nimport { LoadResultCache, createCachedLoad } from '../load-result-cache';\nimport {PostcssConfiguration} from '../postcss-configuration';\n\n/**\n * Configuration options for handling Sass-specific deprecations in a stylesheet plugin.\n */\nexport type StylesheetPluginsass = Pick<\n Options<'async'>,\n 'futureDeprecations' | 'fatalDeprecations' | 'silenceDeprecations'\n>;\n\n/**\n * Convenience type for a postcss processor.\n */\ntype PostcssProcessor = import('postcss').Processor;\n\n/**\n * The lazy-loaded instance of the postcss stylesheet postprocessor.\n * It is only imported and initialized if postcss is needed.\n */\nlet postcss: (typeof import('postcss'))['default'] | undefined;\n\n/**\n * An object containing the plugin options to use when processing stylesheets.\n */\nexport interface StylesheetPluginOptions {\n /**\n * Controls the use and creation of sourcemaps when processing the stylesheets.\n * If true, sourcemap processing is enabled; if false, disabled.\n */\n sourcemap: boolean;\n\n /**\n * An optional array of paths that will be searched for stylesheets if the default\n * resolution process for the stylesheet language does not succeed.\n */\n includePaths?: string[];\n\n /**\n * Optional component data for any inline styles from Component decorator `styles` fields.\n * The key is an internal angular resource URI and the value is the stylesheet content.\n */\n inlineComponentData?: Record<string, string>;\n\n /**\n * Optional information used to load and configure Tailwind CSS. If present, the postcss\n * will be added to the stylesheet processing with the Tailwind plugin setup as provided\n * by the configuration file.\n */\n tailwindConfiguration?: { file: string; package: string };\n\n /**\n * Optional configuration object for custom postcss usage. If present, postcss will be\n * initialized and used for every stylesheet. This overrides the tailwind integration\n * and any tailwind usage must be manually configured in the custom postcss usage.\n */\n postcssConfiguration?: PostcssConfiguration;\n\n /**\n * Optional Options for configuring Sass behavior.\n */\n sass?: StylesheetPluginsass;\n}\n\n/**\n * An array of keywords that indicate Tailwind CSS processing is required for a stylesheet.\n *\n * Based on https://tailwindcss.com/docs/functions-and-directives\n */\nconst TAILWIND_KEYWORDS = [\n '@tailwind',\n '@layer',\n '@apply',\n '@config',\n 'theme(',\n 'screen(',\n '@screen', // Undocumented in version 3, see: https://github.com/tailwindlabs/tailwindcss/discussions/7516.\n];\n\nexport interface StylesheetLanguage {\n name: string;\n componentFilter: RegExp;\n fileFilter: RegExp;\n process?(\n data: string,\n file: string,\n format: string,\n options: StylesheetPluginOptions,\n build: PluginBuild,\n ): OnLoadResult | Promise<OnLoadResult>;\n}\n\n/**\n * Cached postcss instances that can be re-used between various StylesheetPluginFactory instances.\n */\nconst postcssProcessors = new Map<string, WeakRef<PostcssProcessor>>();\n\nexport class StylesheetPluginFactory {\n constructor(\n private readonly options: StylesheetPluginOptions,\n private readonly cache?: LoadResultCache,\n ) {}\n\n create(language: Readonly<StylesheetLanguage>): Plugin {\n const { cache, options, setupPostcss } = this;\n\n // Return a noop plugin if no load actions are required\n if (!language.process && !options.postcssConfiguration && !options.tailwindConfiguration) {\n return {\n name: 'angular-' + language.name,\n setup() {},\n };\n }\n\n return {\n name: 'angular-' + language.name,\n async setup(build) {\n // Setup postcss if needed\n let postcssProcessor: PostcssProcessor | undefined;\n build.onStart(async () => {\n try {\n postcssProcessor = await setupPostcss;\n } catch {\n return {\n errors: [\n {\n text: 'Unable to load the \"postcss\" stylesheet processor.',\n location: null,\n notes: [\n {\n text:\n 'Ensure that the \"postcss\" Node.js package is installed within the project. ' +\n \"If not present, installation via the project's package manager should resolve the error.\",\n },\n ],\n },\n ],\n };\n }\n });\n\n // Add a load callback to support inline Component styles\n build.onLoad(\n { filter: language.componentFilter, namespace: 'angular:styles/component' },\n createCachedLoad(cache, (args) => {\n const data = options.inlineComponentData?.[args.path];\n assert(\n typeof data === 'string',\n `component style name should always be found [${args.path}]`,\n );\n\n const [format, , filename] = args.path.split(';', 3);\n\n return processStylesheet(\n language,\n data,\n filename,\n format,\n options,\n build,\n postcssProcessor,\n );\n }),\n );\n\n // Add a load callback to support files from disk\n build.onLoad(\n { filter: language.fileFilter, namespace: 'file' },\n createCachedLoad(cache, async (args) => {\n const data = await readFile(args.path, 'utf-8');\n\n return processStylesheet(\n language,\n data,\n args.path,\n extname(args.path).toLowerCase().slice(1),\n options,\n build,\n postcssProcessor,\n );\n }),\n );\n },\n };\n }\n\n private setupPostcssPromise: Promise<PostcssProcessor | undefined> | undefined;\n private get setupPostcss(): Promise<PostcssProcessor | undefined> {\n return (this.setupPostcssPromise ??= this.initPostcss());\n }\n\n private initPostcssCallCount = 0;\n\n /**\n * This method should not be called directly.\n * Use {@link setupPostcss} instead.\n */\n private async initPostcss(): Promise<PostcssProcessor | undefined> {\n assert.equal(++this.initPostcssCallCount, 1, '`initPostcss` was called more than once.');\n\n const { options } = this;\n if (options.postcssConfiguration) {\n const postCssInstanceKey = JSON.stringify(options.postcssConfiguration);\n let postcssProcessor = postcssProcessors.get(postCssInstanceKey)?.deref();\n\n if (!postcssProcessor) {\n postcss ??= (await import('postcss')).default;\n postcssProcessor = postcss();\n for (const [pluginName, pluginOptions] of options.postcssConfiguration.plugins) {\n const { default: plugin } = await import(pluginName);\n if (typeof plugin !== 'function' || plugin.postcss !== true) {\n throw new Error(`Attempted to load invalid Postcss plugin: \"${pluginName}\"`);\n }\n\n postcssProcessor.use(plugin(pluginOptions));\n }\n\n postcssProcessors.set(postCssInstanceKey, new WeakRef(postcssProcessor));\n }\n\n return postcssProcessor;\n } else if (options.tailwindConfiguration) {\n const { package: tailwindPackage, file: config } = options.tailwindConfiguration;\n const postCssInstanceKey = tailwindPackage + ':' + config;\n let postcssProcessor = postcssProcessors.get(postCssInstanceKey)?.deref();\n\n if (!postcssProcessor) {\n postcss ??= (await import('postcss')).default;\n const tailwind = await import(tailwindPackage);\n postcssProcessor = postcss().use(tailwind.default({ config }));\n postcssProcessors.set(postCssInstanceKey, new WeakRef(postcssProcessor));\n }\n\n return postcssProcessor;\n }\n }\n}\n\nasync function processStylesheet(\n language: Readonly<StylesheetLanguage>,\n data: string,\n filename: string,\n format: string,\n options: StylesheetPluginOptions,\n build: PluginBuild,\n postcssProcessor: PostcssProcessor | undefined,\n) {\n let result: OnLoadResult;\n\n // Process the input data if the language requires preprocessing\n if (language.process) {\n result = await language.process(data, filename, format, options, build);\n } else {\n result = {\n contents: data,\n loader: 'css',\n watchFiles: [filename],\n };\n }\n\n // Return early if there are no contents to further process or there are errors\n if (!result.contents || result.errors?.length) {\n return result;\n }\n\n // Only use postcss if Tailwind processing is required or custom postcss is present.\n if (postcssProcessor && (options.postcssConfiguration || hasTailwindKeywords(result.contents))) {\n const postcssResult = await compileString(\n typeof result.contents === 'string'\n ? result.contents\n : Buffer.from(result.contents).toString('utf-8'),\n filename,\n postcssProcessor,\n options,\n );\n\n // Merge results\n if (postcssResult.errors?.length) {\n delete result.contents;\n }\n if (result.warnings && postcssResult.warnings) {\n postcssResult.warnings.unshift(...result.warnings);\n }\n if (result.watchFiles && postcssResult.watchFiles) {\n postcssResult.watchFiles.unshift(...result.watchFiles);\n }\n if (result.watchDirs && postcssResult.watchDirs) {\n postcssResult.watchDirs.unshift(...result.watchDirs);\n }\n result = {\n ...result,\n ...postcssResult,\n };\n }\n\n return result;\n}\n\n/**\n * Searches the provided contents for keywords that indicate Tailwind is used\n * within a stylesheet.\n * @param contents A string or Uint8Array containing UTF-8 text.\n * @returns True, if the contents contains tailwind keywords; False, otherwise.\n */\nfunction hasTailwindKeywords(contents: string | Uint8Array): boolean {\n // TODO: use better search algorithm for keywords\n if (typeof contents === 'string') {\n return TAILWIND_KEYWORDS.some((keyword) => contents.includes(keyword));\n }\n\n // Contents is a Uint8Array\n const data = contents instanceof Buffer ? contents : Buffer.from(contents);\n\n return TAILWIND_KEYWORDS.some((keyword) => data.includes(keyword));\n}\n\n/**\n * Compiles the provided CSS stylesheet data using a provided postcss processor and provides an\n * esbuild load result that can be used directly by an esbuild Plugin.\n * @param data The stylesheet content to process.\n * @param filename The name of the file that contains the data.\n * @param postcssProcessor A postcss processor instance to use.\n * @param options The plugin options to control the processing.\n * @returns An esbuild OnLoaderResult object with the processed content, warnings, and/or errors.\n */\nasync function compileString(\n data: string,\n filename: string,\n postcssProcessor: import('postcss').Processor,\n options: StylesheetPluginOptions,\n): Promise<OnLoadResult> {\n try {\n const postcssResult = await postcssProcessor.process(data, {\n from: filename,\n to: filename,\n map: options.sourcemap && {\n inline: true,\n sourcesContent: true,\n },\n });\n\n const loadResult: OnLoadResult = {\n contents: postcssResult.css,\n loader: 'css',\n };\n\n const rawWarnings = postcssResult.warnings();\n if (rawWarnings.length > 0) {\n const lineMappings = new Map<string, string[] | null>();\n loadResult.warnings = rawWarnings.map((warning) => {\n const file = warning.node.source?.input.file;\n if (file === undefined) {\n return { text: warning.text };\n }\n\n let lines = lineMappings.get(file);\n if (lines === undefined) {\n lines = warning.node.source?.input.css.split(/\\r?\\n/);\n lineMappings.set(file, lines ?? null);\n }\n\n return {\n text: warning.text,\n location: {\n file,\n line: warning.line,\n column: warning.column - 1,\n lineText: lines?.[warning.line - 1],\n },\n };\n });\n }\n\n for (const resultMessage of postcssResult.messages) {\n if (resultMessage.type === 'dependency' && typeof resultMessage['file'] === 'string') {\n loadResult.watchFiles ??= [];\n loadResult.watchFiles.push(resultMessage['file']);\n } else if (\n resultMessage.type === 'dir-dependency' &&\n typeof resultMessage['dir'] === 'string' &&\n typeof resultMessage['glob'] === 'string'\n ) {\n loadResult.watchFiles ??= [];\n const dependencies = await glob(resultMessage['glob'], {\n absolute: true,\n cwd: resultMessage['dir'],\n });\n loadResult.watchFiles.push(...dependencies);\n }\n }\n\n return loadResult;\n } catch (error) {\n postcss ??= (await import('postcss')).default;\n if (error instanceof postcss.CssSyntaxError) {\n const lines = error.source?.split(/\\r?\\n/);\n\n return {\n errors: [\n {\n text: error.reason,\n location: {\n file: error.file,\n line: error.line,\n column: error.column && error.column - 1,\n lineText: error.line === undefined ? undefined : lines?.[error.line - 1],\n },\n },\n ],\n };\n }\n\n throw error;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"stylesheet-plugin-factory.js","sourceRoot":"","sources":["../../../../src/lib/styles/stylesheets/stylesheet-plugin-factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,8DAAiC;AACjC,+CAA4C;AAC5C,yCAAoC;AAEpC,2CAAkC;AAClC,4DAAyE;AAgBzE;;;GAGG;AACH,IAAI,OAA0D,CAAC;AA4C/D;;;;GAIG;AACH,MAAM,iBAAiB,GAAG;IACxB,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,SAAS;IACT,SAAS,EAAE,gGAAgG;CAC5G,CAAC;AAeF;;GAEG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAqC,CAAC;AAEvE,MAAa,uBAAuB;IAClC,YACmB,OAAgC,EAChC,KAAuB;QADvB,YAAO,GAAP,OAAO,CAAyB;QAChC,UAAK,GAAL,KAAK,CAAkB;QA2FlC,yBAAoB,GAAG,CAAC,CAAC;IA1F9B,CAAC;IAEJ,MAAM,CAAC,QAAsC;QAC3C,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;QAE9C,uDAAuD;QACvD,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,oBAAoB,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,CAAC;YACzF,OAAO;gBACL,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC,IAAI;gBAChC,KAAK,KAAI,CAAC;aACX,CAAC;QACJ,CAAC;QAED,OAAO;YACL,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC,IAAI;YAChC,KAAK,CAAC,KAAK,CAAC,KAAK;gBACf,0BAA0B;gBAC1B,IAAI,gBAA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C,OAAO;gBACL,MAAM,EAAE;oBACN;wBACE,IAAI,EAAE,KAAK,CAAC,MAAM;wBAClB,QAAQ,EAAE;4BACR,IAAI,EAAE,KAAK,CAAC,IAAI;4BAChB,IAAI,EAAE,KAAK,CAAC,IAAI;4BAChB,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;4BACxC,QAAQ,EAAE,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAG,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;yBACzE;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import type { OnLoadResult, Plugin, PluginBuild } from 'esbuild';\nimport assert from 'node:assert';\nimport { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport type { Options } from 'sass';\nimport { glob } from 'tinyglobby';\nimport { LoadResultCache, createCachedLoad } from '../load-result-cache';\nimport {PostcssConfiguration} from '../postcss-configuration';\n\n/**\n * Configuration options for handling Sass-specific deprecations in a stylesheet plugin.\n */\nexport type StylesheetPluginsass = Pick<\n Options<'async'>,\n 'futureDeprecations' | 'fatalDeprecations' | 'silenceDeprecations'\n>;\n\n/**\n * Convenience type for a postcss processor.\n */\ntype PostcssProcessor = import('postcss').Processor;\n\n/**\n * The lazy-loaded instance of the postcss stylesheet postprocessor.\n * It is only imported and initialized if postcss is needed.\n */\nlet postcss: (typeof import('postcss'))['default'] | undefined;\n\n/**\n * An object containing the plugin options to use when processing stylesheets.\n */\nexport interface StylesheetPluginOptions {\n /**\n * Controls the use and creation of sourcemaps when processing the stylesheets.\n * If true, sourcemap processing is enabled; if false, disabled.\n */\n sourcemap: boolean;\n\n /**\n * An optional array of paths that will be searched for stylesheets if the default\n * resolution process for the stylesheet language does not succeed.\n */\n includePaths?: string[];\n\n /**\n * Optional component data for any inline styles from Component decorator `styles` fields.\n * The key is an internal angular resource URI and the value is the stylesheet content.\n */\n inlineComponentData?: Record<string, string>;\n\n /**\n * Optional information used to load and configure Tailwind CSS. If present, the postcss\n * will be added to the stylesheet processing with the Tailwind plugin setup as provided\n * by the configuration file.\n */\n tailwindConfiguration?: { file: string; package: string };\n\n /**\n * Optional configuration object for custom postcss usage. If present, postcss will be\n * initialized and used for every stylesheet. This overrides the tailwind integration\n * and any tailwind usage must be manually configured in the custom postcss usage.\n */\n postcssConfiguration?: PostcssConfiguration;\n\n /**\n * Optional Options for configuring Sass behavior.\n */\n sass?: StylesheetPluginsass;\n}\n\n/**\n * An array of keywords that indicate Tailwind CSS processing is required for a stylesheet.\n *\n * Based on https://tailwindcss.com/docs/functions-and-directives\n */\nconst TAILWIND_KEYWORDS = [\n '@tailwind',\n '@layer',\n '@apply',\n '@config',\n 'theme(',\n 'screen(',\n '@screen', // Undocumented in version 3, see: https://github.com/tailwindlabs/tailwindcss/discussions/7516.\n];\n\nexport interface StylesheetLanguage {\n name: string;\n componentFilter: RegExp;\n fileFilter: RegExp;\n process?(\n data: string,\n file: string,\n format: string,\n options: StylesheetPluginOptions,\n build: PluginBuild,\n ): OnLoadResult | Promise<OnLoadResult>;\n}\n\n/**\n * Cached postcss instances that can be re-used between various StylesheetPluginFactory instances.\n */\nconst postcssProcessors = new Map<string, WeakRef<PostcssProcessor>>();\n\nexport class StylesheetPluginFactory {\n constructor(\n private readonly options: StylesheetPluginOptions,\n private readonly cache?: LoadResultCache,\n ) {}\n\n create(language: Readonly<StylesheetLanguage>): Plugin {\n const { cache, options, setupPostcss } = this;\n\n // Return a noop plugin if no load actions are required\n if (!language.process && !options.postcssConfiguration && !options.tailwindConfiguration) {\n return {\n name: 'angular-' + language.name,\n setup() {},\n };\n }\n\n return {\n name: 'angular-' + language.name,\n async setup(build) {\n // Setup postcss if needed\n let postcssProcessor: PostcssProcessor | undefined;\n build.onStart(async () => {\n try {\n postcssProcessor = await setupPostcss;\n } catch {\n return {\n errors: [\n {\n text: 'Unable to load the \"postcss\" stylesheet processor.',\n location: null,\n notes: [\n {\n text:\n 'Ensure that the \"postcss\" Node.js package is installed within the project. ' +\n \"If not present, installation via the project's package manager should resolve the error.\",\n },\n ],\n },\n ],\n };\n }\n });\n\n // Add a load callback to support inline Component styles\n build.onLoad(\n { filter: language.componentFilter, namespace: 'angular:styles/component' },\n createCachedLoad(cache, (args) => {\n const data = options.inlineComponentData?.[args.path];\n assert(\n typeof data === 'string',\n `component style name should always be found [${args.path}]`,\n );\n\n const [format, , filename] = args.path.split(';', 3);\n\n return processStylesheet(\n language,\n data,\n filename,\n format,\n options,\n build,\n postcssProcessor,\n );\n }),\n );\n\n // Add a load callback to support files from disk\n build.onLoad(\n { filter: language.fileFilter, namespace: 'file' },\n createCachedLoad(cache, async (args) => {\n const data = await readFile(args.path, 'utf-8');\n\n return processStylesheet(\n language,\n data,\n args.path,\n extname(args.path).toLowerCase().slice(1),\n options,\n build,\n postcssProcessor,\n );\n }),\n );\n },\n };\n }\n\n private setupPostcssPromise: Promise<PostcssProcessor | undefined> | undefined;\n private get setupPostcss(): Promise<PostcssProcessor | undefined> {\n return (this.setupPostcssPromise ??= this.initPostcss());\n }\n\n private initPostcssCallCount = 0;\n\n /**\n * This method should not be called directly.\n * Use {@link setupPostcss} instead.\n */\n private async initPostcss(): Promise<PostcssProcessor | undefined> {\n assert.equal(++this.initPostcssCallCount, 1, '`initPostcss` was called more than once.');\n\n const { options } = this;\n if (options.postcssConfiguration) {\n const postCssInstanceKey = JSON.stringify(options.postcssConfiguration);\n let postcssProcessor = postcssProcessors.get(postCssInstanceKey)?.deref();\n\n if (!postcssProcessor) {\n postcss ??= (await import('postcss')).default;\n postcssProcessor = postcss();\n for (const [pluginName, pluginOptions] of options.postcssConfiguration.plugins) {\n const { default: plugin } = await import(pluginName);\n if (typeof plugin !== 'function' || plugin.postcss !== true) {\n throw new Error(`Attempted to load invalid Postcss plugin: \"${pluginName}\"`);\n }\n\n postcssProcessor.use(plugin(pluginOptions));\n }\n\n postcssProcessors.set(postCssInstanceKey, new WeakRef(postcssProcessor));\n }\n\n return postcssProcessor;\n } else if (options.tailwindConfiguration) {\n const { package: tailwindPackage, file: config } = options.tailwindConfiguration;\n const postCssInstanceKey = tailwindPackage + ':' + config;\n let postcssProcessor = postcssProcessors.get(postCssInstanceKey)?.deref();\n\n if (!postcssProcessor) {\n postcss ??= (await import('postcss')).default;\n const tailwind = await import(tailwindPackage);\n postcssProcessor = postcss().use(tailwind.default({ config }));\n postcssProcessors.set(postCssInstanceKey, new WeakRef(postcssProcessor));\n }\n\n return postcssProcessor;\n }\n }\n}\n\nasync function processStylesheet(\n language: Readonly<StylesheetLanguage>,\n data: string,\n filename: string,\n format: string,\n options: StylesheetPluginOptions,\n build: PluginBuild,\n postcssProcessor: PostcssProcessor | undefined,\n) {\n let result: OnLoadResult;\n\n // Process the input data if the language requires preprocessing\n if (language.process) {\n result = await language.process(data, filename, format, options, build);\n } else {\n result = {\n contents: data,\n loader: 'css',\n watchFiles: [filename],\n };\n }\n\n // Return early if there are no contents to further process or there are errors\n if (!result.contents || result.errors?.length) {\n return result;\n }\n\n // Only use postcss if Tailwind processing is required or custom postcss is present.\n if (postcssProcessor && (options.postcssConfiguration || hasTailwindKeywords(result.contents))) {\n const postcssResult = await compileString(\n typeof result.contents === 'string'\n ? result.contents\n : Buffer.from(result.contents).toString('utf-8'),\n filename,\n postcssProcessor,\n options,\n );\n\n // Merge results\n if (postcssResult.errors?.length) {\n delete result.contents;\n }\n if (result.warnings && postcssResult.warnings) {\n postcssResult.warnings.unshift(...result.warnings);\n }\n if (result.watchFiles && postcssResult.watchFiles) {\n postcssResult.watchFiles.unshift(...result.watchFiles);\n }\n if (result.watchDirs && postcssResult.watchDirs) {\n postcssResult.watchDirs.unshift(...result.watchDirs);\n }\n result = {\n ...result,\n ...postcssResult,\n };\n }\n\n return result;\n}\n\n/**\n * Searches the provided contents for keywords that indicate Tailwind is used\n * within a stylesheet.\n * @param contents A string or Uint8Array containing UTF-8 text.\n * @returns True, if the contents contains tailwind keywords; False, otherwise.\n */\nfunction hasTailwindKeywords(contents: string | Uint8Array): boolean {\n // TODO: use better search algorithm for keywords\n if (typeof contents === 'string') {\n return TAILWIND_KEYWORDS.some((keyword) => contents.includes(keyword));\n }\n\n // Contents is a Uint8Array\n const data = contents instanceof Buffer ? contents : Buffer.from(contents);\n\n return TAILWIND_KEYWORDS.some((keyword) => data.includes(keyword));\n}\n\n/**\n * Compiles the provided CSS stylesheet data using a provided postcss processor and provides an\n * esbuild load result that can be used directly by an esbuild Plugin.\n * @param data The stylesheet content to process.\n * @param filename The name of the file that contains the data.\n * @param postcssProcessor A postcss processor instance to use.\n * @param options The plugin options to control the processing.\n * @returns An esbuild OnLoaderResult object with the processed content, warnings, and/or errors.\n */\nasync function compileString(\n data: string,\n filename: string,\n postcssProcessor: import('postcss').Processor,\n options: StylesheetPluginOptions,\n): Promise<OnLoadResult> {\n try {\n const postcssResult = await postcssProcessor.process(data, {\n from: filename,\n to: filename,\n map: options.sourcemap && {\n inline: true,\n sourcesContent: true,\n },\n });\n\n const loadResult: OnLoadResult = {\n contents: postcssResult.css,\n loader: 'css',\n };\n\n const rawWarnings = postcssResult.warnings();\n if (rawWarnings.length > 0) {\n const lineMappings = new Map<string, string[] | null>();\n loadResult.warnings = rawWarnings.map((warning) => {\n const file = warning.node.source?.input.file;\n if (file === undefined) {\n return { text: warning.text };\n }\n\n let lines = lineMappings.get(file);\n if (lines === undefined) {\n lines = warning.node.source?.input.css.split(/\\r?\\n/);\n lineMappings.set(file, lines ?? null);\n }\n\n return {\n text: warning.text,\n location: {\n file,\n line: warning.line,\n column: warning.column - 1,\n lineText: lines?.[warning.line - 1],\n },\n };\n });\n }\n\n for (const resultMessage of postcssResult.messages) {\n if (resultMessage.type === 'dependency' && typeof resultMessage['file'] === 'string') {\n loadResult.watchFiles ??= [];\n loadResult.watchFiles.push(resultMessage['file']);\n } else if (\n resultMessage.type === 'dir-dependency' &&\n typeof resultMessage['dir'] === 'string' &&\n typeof resultMessage['glob'] === 'string'\n ) {\n loadResult.watchFiles ??= [];\n const dependencies = await glob(resultMessage['glob'], {\n absolute: true,\n cwd: resultMessage['dir'],\n });\n loadResult.watchFiles.push(...dependencies);\n }\n }\n\n return loadResult;\n } catch (error) {\n postcss ??= (await import('postcss')).default;\n if (error instanceof postcss.CssSyntaxError) {\n const lines = error.source?.split(/\\r?\\n/);\n\n return {\n errors: [\n {\n text: error.reason,\n location: {\n file: error.file,\n line: error.line,\n column: error.column && error.column - 1,\n lineText: error.line === undefined ? undefined : lines?.[error.line - 1],\n },\n },\n ],\n };\n }\n\n throw error;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ng-packagr",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20.0.0-next.0",
|
|
4
4
|
"description": "Compile and package Angular libraries in Angular Package Format (APF)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"apf",
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
"convert-source-map": "^2.0.0",
|
|
48
48
|
"dependency-graph": "^1.0.0",
|
|
49
49
|
"esbuild": "^0.25.0",
|
|
50
|
-
"fast-glob": "^3.3.2",
|
|
51
50
|
"find-cache-dir": "^3.3.2",
|
|
52
51
|
"injection-js": "^2.4.0",
|
|
53
52
|
"jsonc-parser": "^3.3.1",
|
|
@@ -56,7 +55,8 @@
|
|
|
56
55
|
"piscina": "^4.7.0",
|
|
57
56
|
"postcss": "^8.4.47",
|
|
58
57
|
"rxjs": "^7.8.1",
|
|
59
|
-
"sass": "^1.81.0"
|
|
58
|
+
"sass": "^1.81.0",
|
|
59
|
+
"tinyglobby": "^0.2.12"
|
|
60
60
|
},
|
|
61
61
|
"optionalDependencies": {
|
|
62
62
|
"rollup": "^4.24.0"
|
package/lib/utils/array.d.ts
DELETED
package/lib/utils/array.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toArray = toArray;
|
|
4
|
-
exports.unique = unique;
|
|
5
|
-
function toArray(value) {
|
|
6
|
-
return [].concat(value);
|
|
7
|
-
}
|
|
8
|
-
function unique(value) {
|
|
9
|
-
return [...new Set(value)];
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=array.js.map
|
package/lib/utils/array.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../../src/lib/utils/array.ts"],"names":[],"mappings":";;AAAA,0BAEC;AAED,wBAEC;AAND,SAAgB,OAAO,CAAI,KAAc;IACvC,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AAED,SAAgB,MAAM,CAAI,KAAU;IAClC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["export function toArray<T>(value: T | T[]): T[] {\n return [].concat(value);\n}\n\nexport function unique<T>(value: T[]): T[] {\n return [...new Set(value)];\n}\n"]}
|
package/lib/utils/glob.d.ts
DELETED
package/lib/utils/glob.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.globFiles = globFiles;
|
|
7
|
-
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
8
|
-
const array_1 = require("./array");
|
|
9
|
-
async function globFiles(pattern, options) {
|
|
10
|
-
const files = await Promise.all((0, array_1.toArray)(pattern).map(p => (0, fast_glob_1.default)(p, options)));
|
|
11
|
-
return files.flatMap(x => x);
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=glob.js.map
|
package/lib/utils/glob.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../../src/lib/utils/glob.ts"],"names":[],"mappings":";;;;;AAGA,8BAIC;AAPD,0DAA0C;AAC1C,mCAAkC;AAE3B,KAAK,UAAU,SAAS,CAAC,OAA0B,EAAE,OAAiB;IAC3E,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,IAAA,eAAO,EAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,mBAAI,EAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAE7E,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import glob, { Options } from 'fast-glob';\nimport { toArray } from './array';\n\nexport async function globFiles(pattern: string | string[], options?: Options): Promise<string[]> {\n const files = await Promise.all(toArray(pattern).map(p => glob(p, options)));\n\n return files.flatMap(x => x);\n}\n"]}
|