ng-packagr 14.0.2 → 14.0.3
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.
|
@@ -15,7 +15,7 @@ export declare class NgccProcessor {
|
|
|
15
15
|
constructor(compilerNgcc: typeof import('@angular/compiler-cli/ngcc'), ngccProcessingCache: NgccProcessingCache, projectPath: string, compilerOptions: ts.CompilerOptions, entryPoints: EntryPointNode[]);
|
|
16
16
|
/** Process the entire node modules tree. */
|
|
17
17
|
process(): Promise<void>;
|
|
18
|
-
/** Process a module and
|
|
18
|
+
/** Process a module and its dependencies. */
|
|
19
19
|
processModule(moduleName: string, resolvedModule: ts.ResolvedModule | ts.ResolvedTypeReferenceDirective): void;
|
|
20
20
|
/**
|
|
21
21
|
* Try resolve a package.json file from the resolved .d.ts file.
|
|
@@ -48,8 +48,10 @@ class NgccProcessor {
|
|
|
48
48
|
}
|
|
49
49
|
/** Process the entire node modules tree. */
|
|
50
50
|
async process() {
|
|
51
|
-
// Under Bazel when running in sandbox mode parts of the filesystem is read-only
|
|
52
|
-
|
|
51
|
+
// Under Bazel when running in sandbox mode parts of the filesystem is read-only, or when using
|
|
52
|
+
// Yarn PnP there may not be a node_modules directory. ngcc can't run in those cases, so the
|
|
53
|
+
// processing is skipped.
|
|
54
|
+
if (process.env.BAZEL_TARGET || !this._nodeModulesDirectory) {
|
|
53
55
|
return;
|
|
54
56
|
}
|
|
55
57
|
// Only allow running this during the first run.
|
|
@@ -140,14 +142,16 @@ class NgccProcessor {
|
|
|
140
142
|
}
|
|
141
143
|
}
|
|
142
144
|
}
|
|
143
|
-
/** Process a module and
|
|
145
|
+
/** Process a module and its dependencies. */
|
|
144
146
|
processModule(moduleName, resolvedModule) {
|
|
145
147
|
const resolvedFileName = resolvedModule.resolvedFileName;
|
|
146
|
-
if (!
|
|
148
|
+
if (!this._nodeModulesDirectory ||
|
|
149
|
+
!resolvedFileName ||
|
|
147
150
|
moduleName.startsWith('.') ||
|
|
148
151
|
this.ngccProcessingCache.hasProcessed(moduleName) ||
|
|
149
152
|
this._entryPointsUrl.includes((0, nodes_1.ngUrl)(moduleName))) {
|
|
150
|
-
// Skip when module is unknown, relative, an
|
|
153
|
+
// Skip when module_modules directory is not present, module is unknown, relative, an
|
|
154
|
+
// entrypoint or already processed.
|
|
151
155
|
return;
|
|
152
156
|
}
|
|
153
157
|
const packageJsonPath = this.tryResolvePackage(moduleName, resolvedFileName);
|
|
@@ -201,7 +205,7 @@ class NgccProcessor {
|
|
|
201
205
|
}
|
|
202
206
|
current = path.dirname(current);
|
|
203
207
|
}
|
|
204
|
-
|
|
208
|
+
return null;
|
|
205
209
|
}
|
|
206
210
|
}
|
|
207
211
|
exports.NgccProcessor = NgccProcessor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngcc-processor.js","sourceRoot":"","sources":["../../../src/lib/ngc/ngcc-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAA0C;AAC1C,mCAAoC;AACpC,2BAAuD;AACvD,2CAA6B;AAG7B,+CAA4D;AAC5D,6CAAqD;AACrD,oCAAiE;AACjE,kDAAoC;AAEpC,wEAAwE;AACxE,MAAa,aAAa;IAOxB,YACmB,YAAyD,EACzD,mBAAwC,EACxC,WAAmB,EACnB,eAAmC,EACnC,WAA6B;QAJ7B,iBAAY,GAAZ,YAAY,CAA6C;QACzD,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,gBAAW,GAAX,WAAW,CAAQ;QACnB,oBAAe,GAAf,eAAe,CAAoB;QACnC,gBAAW,GAAX,WAAW,CAAkB;QAR/B,yBAAoB,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QACxE,mBAAc,GAAG,KAAK,CAAC;QAS7B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC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AACH,CAAC","sourcesContent":["import type { Logger } from '@angular/compiler-cli/ngcc';\nimport { spawnSync } from 'child_process';\nimport { createHash } from 'crypto';\nimport { accessSync, constants, existsSync } from 'fs';\nimport * as path from 'path';\nimport ts from 'typescript';\nimport { NgccProcessingCache } from '../ng-package/ngcc-cache';\nimport { EntryPointNode, ngUrl } from '../ng-package/nodes';\nimport { defaultTsConfigPath } from '../ts/tsconfig';\nimport { exists, mkdir, readFile, writeFile } from '../utils/fs';\nimport * as log from '../utils/log';\n\n// Transform a package and its typings when NGTSC is resolving a module.\nexport class NgccProcessor {\n private _logger: NgccLogger;\n private _nodeModulesDirectory: string;\n private _entryPointsUrl: string[];\n private readonly propertiesToConsider = ['es2015', 'browser', 'module', 'main'];\n private skipProcessing = false;\n\n constructor(\n private readonly compilerNgcc: typeof import('@angular/compiler-cli/ngcc'),\n private readonly ngccProcessingCache: NgccProcessingCache,\n private readonly projectPath: string,\n private readonly compilerOptions: ts.CompilerOptions,\n private readonly entryPoints: EntryPointNode[],\n ) {\n this._entryPointsUrl = this.entryPoints.map(({ url }) => ngUrl(url));\n\n const { baseUrl } = this.compilerOptions;\n this._nodeModulesDirectory = this.findNodeModulesDirectory(baseUrl);\n }\n\n /** Process the entire node modules tree. */\n async process(): Promise<void> {\n // Under Bazel when running in sandbox mode parts of the filesystem is read-only.\n if (process.env.BAZEL_TARGET) {\n return;\n }\n\n // Only allow running this during the first run.\n if (this.skipProcessing) {\n return;\n }\n\n // Skip if node_modules are read-only\n const corePackage = this.tryResolvePackage('@angular/core', this._nodeModulesDirectory);\n if (corePackage && isReadOnlyFile(corePackage)) {\n return;\n }\n\n // Perform a ngcc run check to determine if an initial execution is required.\n // If a run hash file exists that matches the current package manager lock file and the\n // project's tsconfig, then an initial ngcc run has already been performed.\n let runHashFilePath: string | undefined;\n const runHashBasePath = path.join(this._nodeModulesDirectory, '.ng-packagr-ngcc');\n const projectBasePath = path.join(this._nodeModulesDirectory, '..');\n try {\n let lockData;\n let lockFile = 'yarn.lock';\n try {\n lockData = await readFile(path.join(projectBasePath, lockFile));\n } catch {\n lockFile = 'package-lock.json';\n lockData = await readFile(path.join(projectBasePath, lockFile));\n }\n\n let ngccConfigData;\n try {\n ngccConfigData = await readFile(path.join(projectBasePath, 'ngcc.config.js'));\n } catch {\n ngccConfigData = '';\n }\n\n const relativeTsconfigPath = path.relative(projectBasePath, this.projectPath);\n const tsconfigData = await readFile(this.projectPath);\n\n // Generate a hash that represents the state of the package lock file and used tsconfig\n const runHash = createHash('sha256')\n .update(lockData)\n .update(lockFile)\n .update(ngccConfigData)\n .update(tsconfigData)\n .update(relativeTsconfigPath)\n .digest('hex');\n\n // The hash is used directly in the file name to mitigate potential read/write race\n // conditions as well as to only require a file existence check\n runHashFilePath = path.join(runHashBasePath, runHash + '.lock');\n\n // If the run hash lock file exists, then ngcc was already run against this project state\n if (await exists(runHashFilePath)) {\n this.skipProcessing = true;\n\n return;\n }\n } catch {\n // Any error means an ngcc execution is needed\n }\n\n const { status, error } = spawnSync(\n process.execPath,\n [\n this.compilerNgcc.ngccMainFilePath,\n '--source' /** basePath */,\n this._nodeModulesDirectory,\n '--properties' /** propertiesToConsider */,\n ...this.propertiesToConsider,\n '--first-only' /** compileAllFormats */,\n '--create-ivy-entry-points' /** createNewEntryPointFormats */,\n '--async',\n '--tsconfig' /** tsConfigPath */,\n path.normalize(this.projectPath) === defaultTsConfigPath ? '' : this.projectPath,\n '--use-program-dependencies',\n '--typings-only' /** typingsOnly */,\n ],\n {\n stdio: ['inherit', process.stderr, process.stderr],\n },\n );\n\n this.skipProcessing = true;\n\n if (status !== 0) {\n const errorMessage = error?.message || '';\n throw new Error(errorMessage + `NGCC failed${errorMessage ? ', see above' : ''}.`);\n }\n\n // ngcc was successful so if a run hash was generated, write it for next time\n if (runHashFilePath) {\n try {\n if (!existsSync(runHashBasePath)) {\n await mkdir(runHashBasePath, { recursive: true });\n }\n await writeFile(runHashFilePath, '');\n } catch {\n // Errors are non-fatal\n }\n }\n }\n\n /** Process a module and it's depedencies. */\n processModule(moduleName: string, resolvedModule: ts.ResolvedModule | ts.ResolvedTypeReferenceDirective): void {\n const resolvedFileName = resolvedModule.resolvedFileName;\n if (\n !resolvedFileName ||\n moduleName.startsWith('.') ||\n this.ngccProcessingCache.hasProcessed(moduleName) ||\n this._entryPointsUrl.includes(ngUrl(moduleName))\n ) {\n // Skip when module is unknown, relative, an entrypoint or already processed.\n return;\n }\n\n const packageJsonPath = this.tryResolvePackage(moduleName, resolvedFileName);\n if (!packageJsonPath) {\n // add it to processed so the second time round we skip this.\n this.ngccProcessingCache.markProcessed(moduleName);\n\n return;\n }\n\n // If the package.json is read only we should skip calling NGCC.\n // With Bazel when running under sandbox the filesystem is read-only.\n if (isReadOnlyFile(packageJsonPath)) {\n // add it to processed so the second time round we skip this.\n this.ngccProcessingCache.markProcessed(moduleName);\n\n return;\n }\n\n this.compilerNgcc.process({\n basePath: this._nodeModulesDirectory,\n targetEntryPointPath: path.dirname(packageJsonPath),\n compileAllFormats: false,\n typingsOnly: true,\n propertiesToConsider: this.propertiesToConsider,\n createNewEntryPointFormats: true,\n logger: this._logger,\n tsConfigPath: this.projectPath === defaultTsConfigPath ? undefined : this.projectPath,\n });\n\n this.ngccProcessingCache.markProcessed(moduleName);\n }\n\n /**\n * Try resolve a package.json file from the resolved .d.ts file.\n */\n private tryResolvePackage(moduleName: string, resolvedFileName: string): string | undefined {\n try {\n return require.resolve(`${moduleName}/package.json`, {\n paths: [resolvedFileName],\n });\n } catch {\n // if it fails this might be a deep import which doesn't have a package.json\n // Ex: @angular/compiler/src/i18n/i18n_ast/package.json\n // or local libraries which don't reside in node_modules\n const packageJsonPath = path.resolve(resolvedFileName, '../package.json');\n\n return existsSync(packageJsonPath) ? packageJsonPath : undefined;\n }\n }\n\n private findNodeModulesDirectory(startPoint: string): string {\n let current = startPoint;\n while (path.dirname(current) !== current) {\n const nodePath = path.join(current, 'node_modules');\n if (existsSync(nodePath)) {\n return nodePath;\n }\n\n current = path.dirname(current);\n }\n\n throw new Error(`Cannot locate the 'node_modules' directory.`);\n }\n}\n\nclass NgccLogger implements Logger {\n level = /** LogLevel.info**/ 1;\n\n debug(...args: string[]) {\n log.debug(args.join(' '));\n }\n\n info(...args: string[]) {\n log.info(args.join(' '));\n }\n\n warn(...args: string[]) {\n log.warn(args.join(' '));\n }\n\n error(...args: string[]) {\n log.error(args.join(' '));\n }\n}\n\nfunction isReadOnlyFile(fileName: string): boolean {\n try {\n accessSync(fileName, constants.W_OK);\n\n return false;\n } catch {\n return true;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ngcc-processor.js","sourceRoot":"","sources":["../../../src/lib/ngc/ngcc-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iDAA0C;AAC1C,mCAAoC;AACpC,2BAAuD;AACvD,2CAA6B;AAG7B,+CAA4D;AAC5D,6CAAqD;AACrD,oCAAiE;AACjE,kDAAoC;AAEpC,wEAAwE;AACxE,MAAa,aAAa;IAOxB,YACmB,YAAyD,EACzD,mBAAwC,EACxC,WAAmB,EACnB,eAAmC,EACnC,WAA6B;QAJ7B,iBAAY,GAAZ,YAAY,CAA6C;QACzD,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,gBAAW,GAAX,WAAW,CAAQ;QACnB,oBAAe,GAAf,eAAe,CAAoB;QACnC,gBAAW,GAAX,WAAW,CAAkB;QAR/B,yBAAoB,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QACxE,mBAAc,GAAG,KAAK,CAAC;QAS7B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,IAAA,aAAK,EAAC,GAAG,CAAC,CAAC,CAAC;QAErE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC;QACzC,IAAI,CAAC,qBAAqB,GAAG,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import { spawnSync } from 'child_process';\nimport { createHash } from 'crypto';\nimport { accessSync, constants, existsSync } from 'fs';\nimport * as path from 'path';\nimport ts from 'typescript';\nimport { NgccProcessingCache } from '../ng-package/ngcc-cache';\nimport { EntryPointNode, ngUrl } from '../ng-package/nodes';\nimport { defaultTsConfigPath } from '../ts/tsconfig';\nimport { exists, mkdir, readFile, writeFile } from '../utils/fs';\nimport * as log from '../utils/log';\n\n// Transform a package and its typings when NGTSC is resolving a module.\nexport class NgccProcessor {\n private _logger: NgccLogger;\n private _nodeModulesDirectory: string | null;\n private _entryPointsUrl: string[];\n private readonly propertiesToConsider = ['es2015', 'browser', 'module', 'main'];\n private skipProcessing = false;\n\n constructor(\n private readonly compilerNgcc: typeof import('@angular/compiler-cli/ngcc'),\n private readonly ngccProcessingCache: NgccProcessingCache,\n private readonly projectPath: string,\n private readonly compilerOptions: ts.CompilerOptions,\n private readonly entryPoints: EntryPointNode[],\n ) {\n this._entryPointsUrl = this.entryPoints.map(({ url }) => ngUrl(url));\n\n const { baseUrl } = this.compilerOptions;\n this._nodeModulesDirectory = this.findNodeModulesDirectory(baseUrl);\n }\n\n /** Process the entire node modules tree. */\n async process(): Promise<void> {\n // Under Bazel when running in sandbox mode parts of the filesystem is read-only, or when using\n // Yarn PnP there may not be a node_modules directory. ngcc can't run in those cases, so the\n // processing is skipped.\n if (process.env.BAZEL_TARGET || !this._nodeModulesDirectory) {\n return;\n }\n\n // Only allow running this during the first run.\n if (this.skipProcessing) {\n return;\n }\n\n // Skip if node_modules are read-only\n const corePackage = this.tryResolvePackage('@angular/core', this._nodeModulesDirectory);\n if (corePackage && isReadOnlyFile(corePackage)) {\n return;\n }\n\n // Perform a ngcc run check to determine if an initial execution is required.\n // If a run hash file exists that matches the current package manager lock file and the\n // project's tsconfig, then an initial ngcc run has already been performed.\n let runHashFilePath: string | undefined;\n const runHashBasePath = path.join(this._nodeModulesDirectory, '.ng-packagr-ngcc');\n const projectBasePath = path.join(this._nodeModulesDirectory, '..');\n try {\n let lockData;\n let lockFile = 'yarn.lock';\n try {\n lockData = await readFile(path.join(projectBasePath, lockFile));\n } catch {\n lockFile = 'package-lock.json';\n lockData = await readFile(path.join(projectBasePath, lockFile));\n }\n\n let ngccConfigData;\n try {\n ngccConfigData = await readFile(path.join(projectBasePath, 'ngcc.config.js'));\n } catch {\n ngccConfigData = '';\n }\n\n const relativeTsconfigPath = path.relative(projectBasePath, this.projectPath);\n const tsconfigData = await readFile(this.projectPath);\n\n // Generate a hash that represents the state of the package lock file and used tsconfig\n const runHash = createHash('sha256')\n .update(lockData)\n .update(lockFile)\n .update(ngccConfigData)\n .update(tsconfigData)\n .update(relativeTsconfigPath)\n .digest('hex');\n\n // The hash is used directly in the file name to mitigate potential read/write race\n // conditions as well as to only require a file existence check\n runHashFilePath = path.join(runHashBasePath, runHash + '.lock');\n\n // If the run hash lock file exists, then ngcc was already run against this project state\n if (await exists(runHashFilePath)) {\n this.skipProcessing = true;\n\n return;\n }\n } catch {\n // Any error means an ngcc execution is needed\n }\n\n const { status, error } = spawnSync(\n process.execPath,\n [\n this.compilerNgcc.ngccMainFilePath,\n '--source' /** basePath */,\n this._nodeModulesDirectory,\n '--properties' /** propertiesToConsider */,\n ...this.propertiesToConsider,\n '--first-only' /** compileAllFormats */,\n '--create-ivy-entry-points' /** createNewEntryPointFormats */,\n '--async',\n '--tsconfig' /** tsConfigPath */,\n path.normalize(this.projectPath) === defaultTsConfigPath ? '' : this.projectPath,\n '--use-program-dependencies',\n '--typings-only' /** typingsOnly */,\n ],\n {\n stdio: ['inherit', process.stderr, process.stderr],\n },\n );\n\n this.skipProcessing = true;\n\n if (status !== 0) {\n const errorMessage = error?.message || '';\n throw new Error(errorMessage + `NGCC failed${errorMessage ? ', see above' : ''}.`);\n }\n\n // ngcc was successful so if a run hash was generated, write it for next time\n if (runHashFilePath) {\n try {\n if (!existsSync(runHashBasePath)) {\n await mkdir(runHashBasePath, { recursive: true });\n }\n await writeFile(runHashFilePath, '');\n } catch {\n // Errors are non-fatal\n }\n }\n }\n\n /** Process a module and its dependencies. */\n processModule(moduleName: string, resolvedModule: ts.ResolvedModule | ts.ResolvedTypeReferenceDirective): void {\n const resolvedFileName = resolvedModule.resolvedFileName;\n if (\n !this._nodeModulesDirectory ||\n !resolvedFileName ||\n moduleName.startsWith('.') ||\n this.ngccProcessingCache.hasProcessed(moduleName) ||\n this._entryPointsUrl.includes(ngUrl(moduleName))\n ) {\n // Skip when module_modules directory is not present, module is unknown, relative, an\n // entrypoint or already processed.\n return;\n }\n\n const packageJsonPath = this.tryResolvePackage(moduleName, resolvedFileName);\n if (!packageJsonPath) {\n // add it to processed so the second time round we skip this.\n this.ngccProcessingCache.markProcessed(moduleName);\n\n return;\n }\n\n // If the package.json is read only we should skip calling NGCC.\n // With Bazel when running under sandbox the filesystem is read-only.\n if (isReadOnlyFile(packageJsonPath)) {\n // add it to processed so the second time round we skip this.\n this.ngccProcessingCache.markProcessed(moduleName);\n\n return;\n }\n\n this.compilerNgcc.process({\n basePath: this._nodeModulesDirectory,\n targetEntryPointPath: path.dirname(packageJsonPath),\n compileAllFormats: false,\n typingsOnly: true,\n propertiesToConsider: this.propertiesToConsider,\n createNewEntryPointFormats: true,\n logger: this._logger,\n tsConfigPath: this.projectPath === defaultTsConfigPath ? undefined : this.projectPath,\n });\n\n this.ngccProcessingCache.markProcessed(moduleName);\n }\n\n /**\n * Try resolve a package.json file from the resolved .d.ts file.\n */\n private tryResolvePackage(moduleName: string, resolvedFileName: string): string | undefined {\n try {\n return require.resolve(`${moduleName}/package.json`, {\n paths: [resolvedFileName],\n });\n } catch {\n // if it fails this might be a deep import which doesn't have a package.json\n // Ex: @angular/compiler/src/i18n/i18n_ast/package.json\n // or local libraries which don't reside in node_modules\n const packageJsonPath = path.resolve(resolvedFileName, '../package.json');\n\n return existsSync(packageJsonPath) ? packageJsonPath : undefined;\n }\n }\n\n private findNodeModulesDirectory(startPoint: string): string | null {\n let current = startPoint;\n while (path.dirname(current) !== current) {\n const nodePath = path.join(current, 'node_modules');\n if (existsSync(nodePath)) {\n return nodePath;\n }\n\n current = path.dirname(current);\n }\n\n return null;\n }\n}\n\nclass NgccLogger implements Logger {\n level = /** LogLevel.info**/ 1;\n\n debug(...args: string[]) {\n log.debug(args.join(' '));\n }\n\n info(...args: string[]) {\n log.info(args.join(' '));\n }\n\n warn(...args: string[]) {\n log.warn(args.join(' '));\n }\n\n error(...args: string[]) {\n log.error(args.join(' '));\n }\n}\n\nfunction isReadOnlyFile(fileName: string): boolean {\n try {\n accessSync(fileName, constants.W_OK);\n\n return false;\n } catch {\n return true;\n }\n}\n"]}
|
|
@@ -48,8 +48,9 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
48
48
|
const node = getNode(fileName);
|
|
49
49
|
entryPoint.dependsOn(node);
|
|
50
50
|
};
|
|
51
|
-
const { flatModuleFile, entryFile } = entryPoint.data.entryPoint;
|
|
51
|
+
const { flatModuleFile, destinationPath, entryFile } = entryPoint.data.entryPoint;
|
|
52
52
|
const flatModuleFileDtsFilename = `${flatModuleFile}.d.ts`;
|
|
53
|
+
const flatModuleFileDtsPath = (0, path_1.ensureUnixPath)(path.join(destinationPath, flatModuleFileDtsFilename));
|
|
53
54
|
const hasIndexEntryFile = path.basename(entryFile.toLowerCase()) === 'index.ts';
|
|
54
55
|
return {
|
|
55
56
|
...compilerHost,
|
|
@@ -71,14 +72,18 @@ function cacheCompilerHost(graph, entryPoint, compilerOptions, moduleResolutionC
|
|
|
71
72
|
},
|
|
72
73
|
writeFile: (fileName, data, writeByteOrderMark, onError, sourceFiles) => {
|
|
73
74
|
if (fileName.endsWith('.d.ts')) {
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
if (fileName === flatModuleFileDtsPath) {
|
|
76
|
+
if (hasIndexEntryFile) {
|
|
77
|
+
// In case the entry file is index.ts, we should not emit the `d.ts` which are a re-export of the `index.ts`.
|
|
78
|
+
// Because it will cause a conflict.
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// Rename file to index.d.ts so that TypeScript can resolve types without
|
|
83
|
+
// them needing to be referenced in the package.json manifest.
|
|
84
|
+
fileName = fileName.replace(flatModuleFileDtsFilename, 'index.d.ts');
|
|
85
|
+
}
|
|
78
86
|
}
|
|
79
|
-
// Rename file to index.d.ts so that TypeScript can resolve types without
|
|
80
|
-
// them needing to be referenced in the package.json manifest.
|
|
81
|
-
fileName = fileName.replace(flatModuleFileDtsFilename, 'index.d.ts');
|
|
82
87
|
sourceFiles.forEach(source => {
|
|
83
88
|
const cache = sourcesFileCache.getOrCreate(source.fileName);
|
|
84
89
|
if (!cache.declarationFileName) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-compiler-host.js","sourceRoot":"","sources":["../../../src/lib/ts/cache-compiler-host.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,mCAAoC;AACpC,2CAA6B;AAC7B,4DAA4B;AAI5B,wCAAqC;AACrC,+CAA8D;AAE9D,wCAA+C;AAE/C,SAAgB,iBAAiB,CAC/B,KAAiB,EACjB,UAA0B,EAC1B,eAAgC,EAChC,qBAA+C,EAC/C,mBAAyC,EACzC,mBAA4D,EAC5D,mBAA8B,UAAU,CAAC,KAAK,CAAC,gBAAgB;IAE/D,MAAM,YAAY,GAAG,oBAAE,CAAC,6BAA6B,CAAC,eAAe,CAAC,CAAC;IAEvE,MAAM,OAAO,GAAG,CAAC,QAAgB,EAAE,EAAE;QACnC,MAAM,OAAO,GAAG,IAAA,eAAO,EAAC,IAAA,qBAAc,EAAC,QAAQ,CAAC,CAAC,CAAC;QAClD,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE9B,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,GAAG,IAAI,WAAI,CAAC,OAAO,CAAC,CAAC;YACzB,KAAK,CAAC,GA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IAAI;qBACd,CAAC,CAAC;oBAEH,MAAM,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;oBAC1C,MAAM,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;oBAC3D,eAAe,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;iBAC/C;gBAED,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;gBAEpB,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;aACnC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAjLD,8CAiLC;AAED,SAAgB,4BAA4B,CAAC,OAAmB;IAC9D,MAAM,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IAClD,OAAO,CAAC,cAAc,GAAG,UAAU,GAAG,UAAU;QAC9C,MAAM,KAAK,GAAsD,kBAAkB,CAAC,GAAG,UAAU,CAAC,CAAC;QAEnG,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE;gBAC9B,IAAI,CAAC,OAAO,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACrE;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAbD,oEAaC","sourcesContent":["import type { CompilerHost, CompilerOptions } from '@angular/compiler-cli';\n\nimport { createHash } from 'crypto';\nimport * as path from 'path';\nimport ts from 'typescript';\nimport { NgPackageConfig } from '../../ng-package.schema';\nimport { FileCache } from '../file-system/file-cache';\nimport { BuildGraph } from '../graph/build-graph';\nimport { Node } from '../graph/node';\nimport { EntryPointNode, fileUrl } from '../ng-package/nodes';\nimport { StylesheetProcessor } from '../styles/stylesheet-processor';\nimport { ensureUnixPath } from '../utils/path';\n\nexport function cacheCompilerHost(\n graph: BuildGraph,\n entryPoint: EntryPointNode,\n compilerOptions: CompilerOptions,\n moduleResolutionCache: ts.ModuleResolutionCache,\n stylesheetProcessor?: StylesheetProcessor,\n inlineStyleLanguage?: NgPackageConfig['inlineStyleLanguage'],\n sourcesFileCache: FileCache = entryPoint.cache.sourcesFileCache,\n): CompilerHost {\n const compilerHost = ts.createIncrementalCompilerHost(compilerOptions);\n\n const getNode = (fileName: string) => {\n const nodeUri = fileUrl(ensureUnixPath(fileName));\n let node = graph.get(nodeUri);\n\n if (!node) {\n node = new Node(nodeUri);\n graph.put(node);\n }\n\n return node;\n };\n\n const addDependee = (fileName: string) => {\n const node = getNode(fileName);\n entryPoint.dependsOn(node);\n };\n\n const { flatModuleFile, entryFile } = entryPoint.data.entryPoint;\n const flatModuleFileDtsFilename = `${flatModuleFile}.d.ts`;\n const hasIndexEntryFile = path.basename(entryFile.toLowerCase()) === 'index.ts';\n\n return {\n ...compilerHost,\n\n // ts specific\n fileExists: (fileName: string) => {\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.exists === undefined) {\n cache.exists = compilerHost.fileExists.call(this, fileName);\n }\n\n return cache.exists;\n },\n\n getSourceFile: (fileName: string, languageVersion: ts.ScriptTarget) => {\n addDependee(fileName);\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (!cache.sourceFile) {\n cache.sourceFile = compilerHost.getSourceFile.call(this, fileName, languageVersion);\n }\n\n return cache.sourceFile;\n },\n\n writeFile: (\n fileName: string,\n data: string,\n writeByteOrderMark: boolean,\n onError?: (message: string) => void,\n sourceFiles?: ReadonlyArray<ts.SourceFile>,\n ) => {\n if (fileName.endsWith('.d.ts')) {\n if (hasIndexEntryFile && path.basename(fileName) === flatModuleFileDtsFilename) {\n // In case the entry file is index.ts, we should not emit the `d.ts` which are a re-export of the `index.ts`.\n // Because it will cause a conflict.\n return;\n }\n\n // Rename file to index.d.ts so that TypeScript can resolve types without\n // them needing to be referenced in the package.json manifest.\n fileName = fileName.replace(flatModuleFileDtsFilename, 'index.d.ts');\n sourceFiles.forEach(source => {\n const cache = sourcesFileCache.getOrCreate(source.fileName);\n if (!cache.declarationFileName) {\n cache.declarationFileName = ensureUnixPath(fileName);\n }\n });\n } else {\n fileName = fileName.replace(/\\.js(\\.map)?$/, '.mjs$1');\n const outputCache = entryPoint.cache.outputCache;\n\n outputCache.set(fileName, {\n content: data,\n version: createHash('sha256').update(data).digest('hex'),\n });\n }\n\n compilerHost.writeFile.call(this, fileName, data, writeByteOrderMark, onError, sourceFiles);\n },\n\n readFile: (fileName: string) => {\n addDependee(fileName);\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n cache.content = compilerHost.readFile.call(this, fileName);\n }\n\n return cache.content;\n },\n\n resolveModuleNames: (moduleNames: string[], containingFile: string) => {\n return moduleNames.map(moduleName => {\n const { resolvedModule } = ts.resolveModuleName(\n moduleName,\n ensureUnixPath(containingFile),\n compilerOptions,\n compilerHost,\n moduleResolutionCache,\n );\n\n return resolvedModule;\n });\n },\n\n resourceNameToFileName: (resourceName: string, containingFilePath: string) => {\n const resourcePath = path.resolve(path.dirname(containingFilePath), resourceName);\n const containingNode = getNode(containingFilePath);\n const resourceNode = getNode(resourcePath);\n containingNode.dependsOn(resourceNode);\n\n return resourcePath;\n },\n\n readResource: async (fileName: string) => {\n addDependee(fileName);\n\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n if (/(?:html?|svg)$/.test(path.extname(fileName))) {\n // template\n cache.content = compilerHost.readFile.call(this, fileName);\n } else {\n // stylesheet\n cache.content = await stylesheetProcessor.process({\n filePath: fileName,\n content: compilerHost.readFile.call(this, fileName),\n });\n }\n\n if (cache.content === undefined) {\n throw new Error(`Cannot read file ${fileName}.`);\n }\n\n cache.exists = true;\n }\n\n return cache.content;\n },\n transformResource: async (data, context) => {\n if (context.resourceFile || context.type !== 'style') {\n return null;\n }\n\n if (inlineStyleLanguage) {\n const key = createHash('sha1').update(data).digest('hex');\n const fileName = `${context.containingFile}-${key}.${inlineStyleLanguage}`;\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n cache.content = await stylesheetProcessor.process({\n filePath: fileName,\n content: data,\n });\n\n const virtualFileNode = getNode(fileName);\n const containingFileNode = getNode(context.containingFile);\n virtualFileNode.dependsOn(containingFileNode);\n }\n\n cache.exists = true;\n\n return { content: cache.content };\n }\n\n return null;\n },\n };\n}\n\nexport function augmentProgramWithVersioning(program: ts.Program): void {\n const baseGetSourceFiles = program.getSourceFiles;\n program.getSourceFiles = function (...parameters) {\n const files: readonly (ts.SourceFile & { version?: string })[] = baseGetSourceFiles(...parameters);\n\n for (const file of files) {\n if (file.version === undefined) {\n file.version = createHash('sha256').update(file.text).digest('hex');\n }\n }\n\n return files;\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"cache-compiler-host.js","sourceRoot":"","sources":["../../../src/lib/ts/cache-compiler-host.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,mCAAoC;AACpC,2CAA6B;AAC7B,4DAA4B;AAI5B,wCAAqC;AACrC,+CAA8D;AAE9D,wCAA+C;AAE/C,SAAgB,iBAAiB,CAC/B,KAAiB,EACjB,UAA0B,EAC1B,eAAgC,EAChC,qBAA+C,EAC/C,mBAAyC,EACzC,mBAA4D,EAC5D,mBAA8B,UAAU,CAAC,KAAK,CAAC,gBAAgB;IAE/D,MAAM,YAAY,GAAG,oBAAE,CAAC,6BAA6B,CAAC,eAAe,CAAC,CAAC;IAEvE,MAAM,OAAO,GAAG,CAAC,QAAgB,EAAE,EAAE;QACnC,MAAM,OAAO,GAAG,IAAA,eAAO,EAAC,IAAA,qBAAc,EAAC,QAAQ,CAAC,CAAC,CAAC;QAClD,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAE9B,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,GAAG,IAAI,WAAI,CAAC,OAAO,CAAC,CAAC;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AAC,OAAO,KAAK,SAAS,EAAE;oBAC/B,KAAK,CAAC,OAAO,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC;wBAChD,QAAQ,EAAE,QAAQ;wBAClB,OAAO,EAAE,IAAI;qBACd,CAAC,CAAC;oBAEH,MAAM,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;oBAC1C,MAAM,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;oBAC3D,eAAe,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;iBAC/C;gBAED,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC;gBAEpB,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;aACnC;YAED,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AArLD,8CAqLC;AAED,SAAgB,4BAA4B,CAAC,OAAmB;IAC9D,MAAM,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IAClD,OAAO,CAAC,cAAc,GAAG,UAAU,GAAG,UAAU;QAC9C,MAAM,KAAK,GAAsD,kBAAkB,CAAC,GAAG,UAAU,CAAC,CAAC;QAEnG,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE;gBAC9B,IAAI,CAAC,OAAO,GAAG,IAAA,mBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;aACrE;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAbD,oEAaC","sourcesContent":["import type { CompilerHost, CompilerOptions } from '@angular/compiler-cli';\n\nimport { createHash } from 'crypto';\nimport * as path from 'path';\nimport ts from 'typescript';\nimport { NgPackageConfig } from '../../ng-package.schema';\nimport { FileCache } from '../file-system/file-cache';\nimport { BuildGraph } from '../graph/build-graph';\nimport { Node } from '../graph/node';\nimport { EntryPointNode, fileUrl } from '../ng-package/nodes';\nimport { StylesheetProcessor } from '../styles/stylesheet-processor';\nimport { ensureUnixPath } from '../utils/path';\n\nexport function cacheCompilerHost(\n graph: BuildGraph,\n entryPoint: EntryPointNode,\n compilerOptions: CompilerOptions,\n moduleResolutionCache: ts.ModuleResolutionCache,\n stylesheetProcessor?: StylesheetProcessor,\n inlineStyleLanguage?: NgPackageConfig['inlineStyleLanguage'],\n sourcesFileCache: FileCache = entryPoint.cache.sourcesFileCache,\n): CompilerHost {\n const compilerHost = ts.createIncrementalCompilerHost(compilerOptions);\n\n const getNode = (fileName: string) => {\n const nodeUri = fileUrl(ensureUnixPath(fileName));\n let node = graph.get(nodeUri);\n\n if (!node) {\n node = new Node(nodeUri);\n graph.put(node);\n }\n\n return node;\n };\n\n const addDependee = (fileName: string) => {\n const node = getNode(fileName);\n entryPoint.dependsOn(node);\n };\n\n const { flatModuleFile, destinationPath, entryFile } = entryPoint.data.entryPoint;\n const flatModuleFileDtsFilename = `${flatModuleFile}.d.ts`;\n const flatModuleFileDtsPath = ensureUnixPath(path.join(destinationPath, flatModuleFileDtsFilename));\n const hasIndexEntryFile = path.basename(entryFile.toLowerCase()) === 'index.ts';\n\n return {\n ...compilerHost,\n\n // ts specific\n fileExists: (fileName: string) => {\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.exists === undefined) {\n cache.exists = compilerHost.fileExists.call(this, fileName);\n }\n\n return cache.exists;\n },\n\n getSourceFile: (fileName: string, languageVersion: ts.ScriptTarget) => {\n addDependee(fileName);\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (!cache.sourceFile) {\n cache.sourceFile = compilerHost.getSourceFile.call(this, fileName, languageVersion);\n }\n\n return cache.sourceFile;\n },\n\n writeFile: (\n fileName: string,\n data: string,\n writeByteOrderMark: boolean,\n onError?: (message: string) => void,\n sourceFiles?: ReadonlyArray<ts.SourceFile>,\n ) => {\n if (fileName.endsWith('.d.ts')) {\n if (fileName === flatModuleFileDtsPath) {\n if (hasIndexEntryFile) {\n // In case the entry file is index.ts, we should not emit the `d.ts` which are a re-export of the `index.ts`.\n // Because it will cause a conflict.\n return;\n } else {\n // Rename file to index.d.ts so that TypeScript can resolve types without\n // them needing to be referenced in the package.json manifest.\n fileName = fileName.replace(flatModuleFileDtsFilename, 'index.d.ts');\n }\n }\n\n sourceFiles.forEach(source => {\n const cache = sourcesFileCache.getOrCreate(source.fileName);\n if (!cache.declarationFileName) {\n cache.declarationFileName = ensureUnixPath(fileName);\n }\n });\n } else {\n fileName = fileName.replace(/\\.js(\\.map)?$/, '.mjs$1');\n const outputCache = entryPoint.cache.outputCache;\n\n outputCache.set(fileName, {\n content: data,\n version: createHash('sha256').update(data).digest('hex'),\n });\n }\n\n compilerHost.writeFile.call(this, fileName, data, writeByteOrderMark, onError, sourceFiles);\n },\n\n readFile: (fileName: string) => {\n addDependee(fileName);\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n cache.content = compilerHost.readFile.call(this, fileName);\n }\n\n return cache.content;\n },\n\n resolveModuleNames: (moduleNames: string[], containingFile: string) => {\n return moduleNames.map(moduleName => {\n const { resolvedModule } = ts.resolveModuleName(\n moduleName,\n ensureUnixPath(containingFile),\n compilerOptions,\n compilerHost,\n moduleResolutionCache,\n );\n\n return resolvedModule;\n });\n },\n\n resourceNameToFileName: (resourceName: string, containingFilePath: string) => {\n const resourcePath = path.resolve(path.dirname(containingFilePath), resourceName);\n const containingNode = getNode(containingFilePath);\n const resourceNode = getNode(resourcePath);\n containingNode.dependsOn(resourceNode);\n\n return resourcePath;\n },\n\n readResource: async (fileName: string) => {\n addDependee(fileName);\n\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n if (/(?:html?|svg)$/.test(path.extname(fileName))) {\n // template\n cache.content = compilerHost.readFile.call(this, fileName);\n } else {\n // stylesheet\n cache.content = await stylesheetProcessor.process({\n filePath: fileName,\n content: compilerHost.readFile.call(this, fileName),\n });\n }\n\n if (cache.content === undefined) {\n throw new Error(`Cannot read file ${fileName}.`);\n }\n\n cache.exists = true;\n }\n\n return cache.content;\n },\n transformResource: async (data, context) => {\n if (context.resourceFile || context.type !== 'style') {\n return null;\n }\n\n if (inlineStyleLanguage) {\n const key = createHash('sha1').update(data).digest('hex');\n const fileName = `${context.containingFile}-${key}.${inlineStyleLanguage}`;\n const cache = sourcesFileCache.getOrCreate(fileName);\n if (cache.content === undefined) {\n cache.content = await stylesheetProcessor.process({\n filePath: fileName,\n content: data,\n });\n\n const virtualFileNode = getNode(fileName);\n const containingFileNode = getNode(context.containingFile);\n virtualFileNode.dependsOn(containingFileNode);\n }\n\n cache.exists = true;\n\n return { content: cache.content };\n }\n\n return null;\n },\n };\n}\n\nexport function augmentProgramWithVersioning(program: ts.Program): void {\n const baseGetSourceFiles = program.getSourceFiles;\n program.getSourceFiles = function (...parameters) {\n const files: readonly (ts.SourceFile & { version?: string })[] = baseGetSourceFiles(...parameters);\n\n for (const file of files) {\n if (file.version === undefined) {\n file.version = createHash('sha256').update(file.text).digest('hex');\n }\n }\n\n return files;\n };\n}\n"]}
|