resolve-pkglock 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs';
|
|
|
2
2
|
import { createRequire, registerHooks, isBuiltin, findPackageJSON } from 'node:module';
|
|
3
3
|
import { join, isAbsolute, dirname } from 'node:path';
|
|
4
4
|
import { platform } from 'node:process';
|
|
5
|
-
import {
|
|
5
|
+
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
6
6
|
import require$$0 from 'crypto';
|
|
7
7
|
import require$$0$3 from 'fs';
|
|
8
8
|
import require$$4 from 'util';
|
|
@@ -17899,7 +17899,7 @@ function requireLib () {
|
|
|
17899
17899
|
|
|
17900
17900
|
var libExports = requireLib();
|
|
17901
17901
|
|
|
17902
|
-
const PACKAGE_REGEX =
|
|
17902
|
+
const PACKAGE_REGEX = /^([a-z\d][-.\w]*|@[a-z\d][-.\w]+\/[a-z\d][-.\w]*)(\/.*)?$/;
|
|
17903
17903
|
function addToRegistry(registry, pkg) {
|
|
17904
17904
|
const { name, version } = pkg;
|
|
17905
17905
|
let versions = registry.get(name);
|
|
@@ -17917,7 +17917,7 @@ async function init(workspaceRoot) {
|
|
|
17917
17917
|
if (lockfile == null) {
|
|
17918
17918
|
throw new Error('no lockfile found');
|
|
17919
17919
|
}
|
|
17920
|
-
const defaultResolve = createRequire(workspaceRoot).resolve, virtualStoreDir = './node_modules/.pnpm', virtualStoreDirMaxLength = platform === 'win32' ? 60 : 120, dirToPackage = {}, packageRegistry = new Map();
|
|
17920
|
+
const defaultResolve = createRequire(workspaceRoot).resolve, virtualStoreDir = join(workspaceRoot, './node_modules/.pnpm'), virtualStoreDirUrlPath = pathToFileURL(virtualStoreDir).toString(), virtualStoreDirMaxLength = platform === 'win32' ? 60 : 120, dirToPackage = {}, packageRegistry = new Map();
|
|
17921
17921
|
for (const [relDepPath, { dependencies, devDependencies, optionalDependencies }] of Object.entries(lockfile.importers)) {
|
|
17922
17922
|
const packageLocation = join(workspaceRoot, relDepPath), { name, version } = JSON.parse(readFileSync(join(packageLocation, 'package.json')).toString()), pkgInfo = {
|
|
17923
17923
|
dependencies,
|
|
@@ -17932,7 +17932,7 @@ async function init(workspaceRoot) {
|
|
|
17932
17932
|
}
|
|
17933
17933
|
if (lockfile.packages) {
|
|
17934
17934
|
for (const [relDepPath, pkg] of Object.entries(lockfile.packages)) {
|
|
17935
|
-
const { dependencies, optionalDependencies } = pkg, packageLocation = join(
|
|
17935
|
+
const { dependencies, optionalDependencies } = pkg, packageLocation = join(virtualStoreDir, libExports$2.depPathToFilename(relDepPath, virtualStoreDirMaxLength)), { name, version } = libExports.nameVerFromPkgSnapshot(relDepPath, pkg), pkgInfo = {
|
|
17936
17936
|
dependencies,
|
|
17937
17937
|
name,
|
|
17938
17938
|
optionalDependencies,
|
|
@@ -17956,12 +17956,25 @@ async function init(workspaceRoot) {
|
|
|
17956
17956
|
if (context.parentURL == null) {
|
|
17957
17957
|
throw new Error('No parentURL!');
|
|
17958
17958
|
}
|
|
17959
|
-
|
|
17960
|
-
|
|
17959
|
+
let pkg;
|
|
17960
|
+
// bottom-up first, because there are packages that introduce multiple package.json in their hierarchy
|
|
17961
|
+
if (context.parentURL.startsWith(virtualStoreDirUrlPath)) {
|
|
17962
|
+
const subpath = context.parentURL.substring(0, context.parentURL.indexOf('/node_modules/', virtualStoreDirUrlPath.length + 1) + 14), // '/node_modules/'.length = 14
|
|
17963
|
+
match = context.parentURL.substring(subpath.length).match(PACKAGE_REGEX);
|
|
17964
|
+
if (match == null) {
|
|
17965
|
+
throw new Error('can\'t parse path');
|
|
17966
|
+
}
|
|
17967
|
+
const [, name] = match;
|
|
17968
|
+
pkg = dirToPackage[join(fileURLToPath(subpath), name)];
|
|
17969
|
+
}
|
|
17970
|
+
else {
|
|
17971
|
+
pkg = dirToPackage[dirname(findPackageJSON(context.parentURL))];
|
|
17972
|
+
}
|
|
17973
|
+
if (pkg == null || pkg.name == null || pkg.version == null) {
|
|
17961
17974
|
throw new Error('unknown package');
|
|
17962
17975
|
}
|
|
17963
17976
|
const { name: parentName, version: parentVersion } = pkg;
|
|
17964
|
-
parent = packageRegistry.get(parentName)?.get(parentVersion);
|
|
17977
|
+
parent = packageRegistry.get(parentName ?? null)?.get(parentVersion ?? null);
|
|
17965
17978
|
}
|
|
17966
17979
|
const match = specifier.match(PACKAGE_REGEX);
|
|
17967
17980
|
if (match == null) {
|
|
@@ -17978,7 +17991,7 @@ async function init(workspaceRoot) {
|
|
|
17978
17991
|
packageLocation = join(parent.packageLocation, version.substring(5));
|
|
17979
17992
|
}
|
|
17980
17993
|
else {
|
|
17981
|
-
packageLocation = join(
|
|
17994
|
+
packageLocation = join(virtualStoreDir, libExports$2.depPathToFilename(`${name}@${version}`, virtualStoreDirMaxLength), 'node_modules', name);
|
|
17982
17995
|
}
|
|
17983
17996
|
if (packageLocation[packageLocation.length - 1] === '/') {
|
|
17984
17997
|
packageLocation = packageLocation.substring(0, packageLocation.length - 1);
|