豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 4505df9

Browse files
committed
fix(ng-dev): yarnpkg lockfile package cannot be bundled with ESM
ESBuild bundles CommonJS packages, but some cannot be due to use of CJS-only features. The yarn lockfile is one package that needs to be kept external for it to leverage CJS features through NodeJS built-in ESM -> CJS interop.
1 parent 70b51cd commit 4505df9

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

ng-dev/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ NG_DEV_EXTERNALS = [
55
# `typescript` is external because we want the project to provide a TypeScript version.
66
# TODO: Figure out how we want to manage dependencies for the dev-infra tool.
77
"typescript",
8+
# Package uses `__filename` and `__dirname` and cannot be bundled in ESM. We do not
9+
# intend to provide interop globals for this as it could hide other significant issues.
10+
"@yarnpkg/lockfile",
811
]
912

1013
ts_library(

ng-dev/utils/resolve-yarn-bin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as path from 'path';
1111
import which from 'which';
1212

1313
import {isNodeJSWrappedError} from './nodejs-errors.js';
14-
import {parse as parseLockfile} from '@yarnpkg/lockfile';
14+
import lockfile from '@yarnpkg/lockfile';
1515
import {parse as parseYaml} from 'yaml';
1616
import {ChildProcess} from './child-process.js';
1717
import {Log} from './logging.js';
@@ -33,7 +33,7 @@ export interface YarnCommandInfo {
3333

3434
/** List of Yarn configuration files and their parsing mechanisms. */
3535
export const yarnConfigFiles: ConfigWithParser[] = [
36-
{fileName: '.yarnrc', parse: (c) => parseLockfile(c).object},
36+
{fileName: '.yarnrc', parse: (c) => lockfile.parse(c).object},
3737
{fileName: '.yarnrc.yml', parse: (c) => parseYaml(c)},
3838
];
3939

ng-dev/utils/version-check.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import * as path from 'path';
1010
import * as fs from 'fs';
11-
import {LockFileObject, parse as parseYarnLockfile} from '@yarnpkg/lockfile';
11+
import lockfile from '@yarnpkg/lockfile';
1212
import {
1313
ngDevNpmPackageName,
1414
workspaceRelativePackageJsonPath,
@@ -34,7 +34,7 @@ export async function verifyNgDevToolIsUpToDate(workspacePath: string): Promise<
3434
try {
3535
const lockFileContent = fs.readFileSync(workspaceDirLockFile, 'utf8');
3636
const packageJson = JSON.parse(fs.readFileSync(workspacePackageJsonFile, 'utf8')) as any;
37-
const lockFile = parseYarnLockfile(lockFileContent);
37+
const lockFile = lockfile.parse(lockFileContent);
3838

3939
if (lockFile.type !== 'success') {
4040
throw Error('Unable to parse workspace lock file. Please ensure the file is valid.');
@@ -45,7 +45,7 @@ export async function verifyNgDevToolIsUpToDate(workspacePath: string): Promise<
4545
return true;
4646
}
4747

48-
const lockFileObject = lockFile.object as LockFileObject;
48+
const lockFileObject = lockFile.object as lockfile.LockFileObject;
4949
const devInfraPkgVersion =
5050
packageJson?.dependencies?.[ngDevNpmPackageName] ??
5151
packageJson?.devDependencies?.[ngDevNpmPackageName] ??

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@types/tmp": "^0.2.1",
4646
"@types/uuid": "^8.3.1",
4747
"@types/yargs": "^17.0.0",
48+
"@yarnpkg/lockfile": "^1.1.0",
4849
"browser-sync": "^2.27.7",
4950
"clang-format": "1.8.0",
5051
"prettier": "2.7.0",
@@ -105,7 +106,6 @@
105106
"@types/wait-on": "^5.3.1",
106107
"@types/which": "^2.0.1",
107108
"@types/yarnpkg__lockfile": "^1.1.5",
108-
"@yarnpkg/lockfile": "^1.1.0",
109109
"chalk": "^5.0.1",
110110
"cli-progress": "^3.7.0",
111111
"conventional-commits-parser": "^3.2.1",

tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
true,
99
{
1010
"noNamedExports": [
11+
"@yarnpkg/lockfile",
1112
"typescript",
1213
"multimatch",
1314
"semver",

0 commit comments

Comments
 (0)