vike 0.4.228-commit-8d90991 → 0.4.228-commit-84954ae
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/cjs/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/handleAssetsManifest.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/pluginBuildApp.js +1 -1
- package/dist/cjs/node/plugin/plugins/build/pluginBuildConfig.js +3 -10
- package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +1 -4
- package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +11 -3
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +2 -7
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +13 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +14 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/cjs/node/plugin/shared/getFilePath.js +2 -2
- package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +7 -19
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/prerender/runPrerender.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -1
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/shared/getPageFiles/fileTypes.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +3 -7
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/isImportPath.js +21 -0
- package/dist/cjs/utils/{isNpmPackage.js → parseNpmPackage.js} +23 -23
- package/dist/cjs/utils/path.js +12 -2
- package/dist/cjs/utils/requireResolve.js +98 -39
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
- package/dist/esm/node/plugin/plugins/build/handleAssetsManifest.js +2 -2
- package/dist/esm/node/plugin/plugins/build/pluginBuildApp.js +2 -2
- package/dist/esm/node/plugin/plugins/build/pluginBuildConfig.js +4 -11
- package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +2 -5
- package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +2 -2
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/commonConfig.js +12 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +3 -8
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.d.ts → pointerImports.d.ts} +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +14 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +14 -10
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +1 -1
- package/dist/esm/node/plugin/shared/getFilePath.js +3 -3
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +8 -20
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/prerender/runPrerender.js +2 -2
- package/dist/esm/node/runtime/globalContext.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/VikeNamespace.d.ts +8 -8
- package/dist/esm/shared/getPageFiles/fileTypes.js +1 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +3 -7
- package/dist/esm/shared/types.d.ts +4 -4
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/isImportPath.d.ts +4 -0
- package/dist/esm/utils/isImportPath.js +19 -0
- package/dist/esm/utils/parseNpmPackage.d.ts +17 -0
- package/dist/esm/utils/{isNpmPackage.js → parseNpmPackage.js} +23 -23
- package/dist/esm/utils/path.d.ts +1 -1
- package/dist/esm/utils/path.js +12 -2
- package/dist/esm/utils/requireResolve.d.ts +20 -7
- package/dist/esm/utils/requireResolve.js +98 -39
- package/package.json +1 -1
- package/dist/esm/utils/isNpmPackage.d.ts +0 -17
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { isImportPathNpmPackage };
|
|
2
|
+
export { isImportPathNpmPackageOrPathAlias };
|
|
3
|
+
export { assertIsImportPathNpmPackage };
|
|
4
|
+
export { isPathAliasRecommended };
|
|
5
5
|
/* Currently not used
|
|
6
6
|
export { isNpmPackageName }
|
|
7
7
|
export { getNpmPackageName }
|
|
8
8
|
export { getNpmPackageImportPath }
|
|
9
9
|
*/
|
|
10
10
|
// For ./isNpmPackage.spec.ts
|
|
11
|
-
export {
|
|
11
|
+
export { parseNpmPackage };
|
|
12
12
|
export { isDistinguishable };
|
|
13
13
|
import { assert } from './assert.js';
|
|
14
14
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
15
15
|
assertIsNotBrowser();
|
|
16
|
-
function
|
|
16
|
+
function isImportPathNpmPackage(str, { cannotBePathAlias }) {
|
|
17
17
|
assert(cannotBePathAlias);
|
|
18
|
-
return
|
|
18
|
+
return isImportPathNpmPackageOrPathAlias(str);
|
|
19
19
|
}
|
|
20
20
|
// We cannot distinguish path aliases that look like npm package imports
|
|
21
|
-
function
|
|
22
|
-
const res =
|
|
21
|
+
function isImportPathNpmPackageOrPathAlias(str) {
|
|
22
|
+
const res = parseNpmPackage(str);
|
|
23
23
|
return res !== null;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
assert(
|
|
27
|
-
// If `str` is a path alias that looks like an npm package =>
|
|
25
|
+
function assertIsImportPathNpmPackage(str) {
|
|
26
|
+
assert(isImportPathNpmPackage(str, {
|
|
27
|
+
// If `str` is a path alias that looks like an npm package => assertIsImportPathNpmPackage() is erroneous but that's okay because the assertion will eventually fail for some other user using a disambiguated path alias.
|
|
28
28
|
cannotBePathAlias: true
|
|
29
29
|
}), str);
|
|
30
30
|
}
|
|
31
31
|
function isNpmPackageName(str) {
|
|
32
|
-
const res =
|
|
32
|
+
const res = parseNpmPackage(str);
|
|
33
33
|
return res !== null && res.importPath === null;
|
|
34
34
|
}
|
|
35
35
|
function getNpmPackageName(str) {
|
|
36
|
-
const res =
|
|
36
|
+
const res = parseNpmPackage(str);
|
|
37
37
|
if (!res)
|
|
38
38
|
return null;
|
|
39
39
|
return res.pkgName;
|
|
40
40
|
}
|
|
41
41
|
function getNpmPackageImportPath(str) {
|
|
42
|
-
const res =
|
|
42
|
+
const res = parseNpmPackage(str);
|
|
43
43
|
if (!res)
|
|
44
44
|
return null;
|
|
45
45
|
return res.importPath;
|
|
46
46
|
}
|
|
47
|
-
function
|
|
47
|
+
function isPathAliasRecommended(alias) {
|
|
48
48
|
// Cannot be distinguished from npm package names
|
|
49
49
|
if (!isDistinguishable(alias))
|
|
50
50
|
return false;
|
|
@@ -60,14 +60,14 @@ function isValidPathAlias(alias) {
|
|
|
60
60
|
return true;
|
|
61
61
|
}
|
|
62
62
|
function isDistinguishable(alias) {
|
|
63
|
-
return (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
return (parseNpmPackage(alias) === null &&
|
|
64
|
+
parseNpmPackage(`${alias}fake-path`) === null &&
|
|
65
|
+
parseNpmPackage(`${alias}/fake-path`) === null &&
|
|
66
|
+
parseNpmPackage(`${alias}fake/deep/path`) === null &&
|
|
67
|
+
parseNpmPackage(`${alias}/fake/deep/path`) === null &&
|
|
68
68
|
// See note about '-' in ./isNpmPackageName.spec.ts
|
|
69
69
|
// ```ts
|
|
70
|
-
// expect(
|
|
70
|
+
// expect(parseNpmPackage('-')).toBe(null) // actually wrong: https://www.npmjs.com/package/-
|
|
71
71
|
// ```
|
|
72
72
|
!alias.startsWith('-'));
|
|
73
73
|
}
|
|
@@ -75,7 +75,7 @@ function isDistinguishable(alias) {
|
|
|
75
75
|
// - https://www.npmjs.com/package/-
|
|
76
76
|
// The correct logic is complex, see https://github.com/npm/validate-npm-package-name
|
|
77
77
|
// We don't need to be accurate: are there npm packages with weird names that are actually being used?
|
|
78
|
-
function
|
|
78
|
+
function parseNpmPackage(str) {
|
|
79
79
|
if (!str)
|
|
80
80
|
return null;
|
|
81
81
|
let scope = null;
|
package/dist/esm/utils/path.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ declare function pathJoin(path1: string, path2: string): string;
|
|
|
11
11
|
/**********************/
|
|
12
12
|
declare function toPosixPath(path: string): string;
|
|
13
13
|
declare function assertPosixPath(path: string): void;
|
|
14
|
-
declare function pathIsRelative(
|
|
14
|
+
declare function pathIsRelative(path: string): boolean;
|
package/dist/esm/utils/path.js
CHANGED
|
@@ -42,6 +42,16 @@ function assertPosixPath(path) {
|
|
|
42
42
|
assert(path);
|
|
43
43
|
assert(!path.includes('\\'), errMsg(path));
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
// See also `import { isImportPathRelative } from './isImportPath.js'`
|
|
46
|
+
function pathIsRelative(path) {
|
|
47
|
+
assertPosixPath(path);
|
|
48
|
+
if (path.startsWith('./') || path.startsWith('../')) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
/* Not true if `path` starts with a hidden directory (i.e. a directory with a name that starts with `.`)
|
|
53
|
+
assert(!path.startsWith('.'))
|
|
54
|
+
*/
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
47
57
|
}
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
export { requireResolve };
|
|
2
1
|
export { requireResolveOptional };
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
declare function
|
|
8
|
-
|
|
2
|
+
export { requireResolveOptionalDir };
|
|
3
|
+
export { requireResolveNpmPackage };
|
|
4
|
+
export { requireResolveVikeDistFile };
|
|
5
|
+
export { getVikeNodeModulesRoot };
|
|
6
|
+
declare function requireResolveOptional({ importPath, importerFile, userRootDir }: {
|
|
7
|
+
importPath: string;
|
|
8
|
+
importerFile: string;
|
|
9
|
+
userRootDir: string;
|
|
10
|
+
}): string | null;
|
|
11
|
+
declare function requireResolveOptionalDir({ importPath, importerDir, userRootDir }: {
|
|
12
|
+
importPath: string;
|
|
13
|
+
importerDir: string;
|
|
14
|
+
userRootDir: string;
|
|
15
|
+
}): string | null;
|
|
16
|
+
declare function requireResolveNpmPackage({ importPathNpmPackage, userRootDir }: {
|
|
17
|
+
importPathNpmPackage: string;
|
|
18
|
+
userRootDir: string;
|
|
19
|
+
}): string;
|
|
20
|
+
declare function requireResolveVikeDistFile(vikeDistFile: `dist/esm/${string}`): string;
|
|
21
|
+
declare function getVikeNodeModulesRoot(): string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { requireResolve };
|
|
2
1
|
export { requireResolveOptional };
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
2
|
+
export { requireResolveOptionalDir };
|
|
3
|
+
export { requireResolveNpmPackage };
|
|
4
|
+
export { requireResolveVikeDistFile };
|
|
5
|
+
export { getVikeNodeModulesRoot };
|
|
5
6
|
import { assert } from './assert.js';
|
|
6
7
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
7
8
|
import { assertIsNotProductionRuntime } from './assertSetup.js';
|
|
@@ -9,68 +10,94 @@ import { assertPosixPath, toPosixPath } from './path.js';
|
|
|
9
10
|
import { scriptFileExtensionList } from './isScriptFile.js';
|
|
10
11
|
import { createRequire } from 'node:module';
|
|
11
12
|
import path from 'node:path';
|
|
13
|
+
import { assertIsImportPathNpmPackage, isImportPathNpmPackageOrPathAlias } from './parseNpmPackage.js';
|
|
12
14
|
// @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
13
15
|
const importMetaUrl = import.meta.url;
|
|
14
|
-
const require_ = createRequire(importMetaUrl);
|
|
15
16
|
assertIsNotBrowser();
|
|
16
17
|
assertIsNotProductionRuntime();
|
|
17
|
-
function requireResolve_(importPath,
|
|
18
|
-
assertPosixPath(
|
|
18
|
+
function requireResolve_(importPath, importerFile, options) {
|
|
19
|
+
assertPosixPath(importerFile);
|
|
19
20
|
assertPosixPath(importPath);
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
assertPosixPath(importMetaUrl);
|
|
22
|
+
assert(path.posix.basename(importerFile).includes('.'), { cwd: importerFile });
|
|
23
|
+
const importerPath = addFilePrefix(importerFile);
|
|
24
|
+
const require_ = createRequire(importerPath);
|
|
22
25
|
if (!options?.doNotHandleFileExtension) {
|
|
23
|
-
|
|
26
|
+
addFileExtensionsToRequireResolve(require_);
|
|
24
27
|
importPath = removeFileExtention(importPath);
|
|
25
28
|
}
|
|
29
|
+
const paths = !options?.paths
|
|
30
|
+
? undefined
|
|
31
|
+
: [
|
|
32
|
+
// Seems like `importerPath` gets overriden by the `paths` argument, so we add it to `paths`. (For example, passing an empty array to `paths` kills the argument passed to `createRequire()`.)
|
|
33
|
+
toDirPath(importerFile),
|
|
34
|
+
...(options?.paths || [])
|
|
35
|
+
];
|
|
26
36
|
let importedFile;
|
|
27
37
|
try {
|
|
28
38
|
// We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
|
|
29
39
|
// - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
|
|
30
|
-
importedFile = require_.resolve(importPath, { paths
|
|
40
|
+
importedFile = require_.resolve(importPath, { paths });
|
|
31
41
|
}
|
|
32
42
|
catch (err) {
|
|
33
|
-
clean();
|
|
34
43
|
return { importedFile: undefined, err, hasFailed: true };
|
|
35
44
|
}
|
|
36
|
-
clean();
|
|
37
45
|
importedFile = toPosixPath(importedFile);
|
|
38
46
|
return { importedFile, err: undefined, hasFailed: false };
|
|
39
47
|
}
|
|
40
|
-
function requireResolveOptional(importPath,
|
|
41
|
-
const
|
|
48
|
+
function requireResolveOptional({ importPath, importerFile, userRootDir }) {
|
|
49
|
+
const paths = getExtraPathsForNpmPackageImport({ importPath, userRootDir });
|
|
50
|
+
const res = requireResolve_(importPath, importerFile, { paths });
|
|
42
51
|
if (res.hasFailed)
|
|
43
52
|
return null;
|
|
44
53
|
return res.importedFile;
|
|
45
54
|
}
|
|
46
|
-
function
|
|
47
|
-
const
|
|
55
|
+
function requireResolveOptionalDir({ importPath, importerDir, userRootDir }) {
|
|
56
|
+
const importerFile = getFakeFilePath(importerDir);
|
|
57
|
+
const paths = getExtraPathsForNpmPackageImport({ importPath, userRootDir });
|
|
58
|
+
const res = requireResolve_(importPath, importerFile, { paths });
|
|
48
59
|
if (res.hasFailed)
|
|
49
60
|
return null;
|
|
50
61
|
return res.importedFile;
|
|
51
62
|
}
|
|
52
|
-
function
|
|
53
|
-
|
|
63
|
+
function requireResolveNpmPackage({ importPathNpmPackage, userRootDir }) {
|
|
64
|
+
assertIsImportPathNpmPackage(importPathNpmPackage);
|
|
65
|
+
const importerFile = getFakeFilePath(userRootDir);
|
|
66
|
+
const paths = getExtraPathsForNpmPackageImport({ importPath: importPathNpmPackage, userRootDir });
|
|
67
|
+
const res = requireResolve_(importPathNpmPackage, importerFile, { paths });
|
|
54
68
|
if (res.hasFailed)
|
|
55
69
|
throw res.err;
|
|
56
70
|
return res.importedFile;
|
|
57
71
|
}
|
|
58
|
-
function
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
72
|
+
function requireResolveVikeDistFile(vikeDistFile) {
|
|
73
|
+
const vikeNodeModulesRoot = getVikeNodeModulesRoot();
|
|
74
|
+
assertPosixPath(vikeNodeModulesRoot);
|
|
75
|
+
assertPosixPath(vikeDistFile);
|
|
76
|
+
const importedFile = path.posix.join(vikeNodeModulesRoot, vikeDistFile);
|
|
77
|
+
// Double check
|
|
78
|
+
{
|
|
79
|
+
const res = requireResolve_(importedFile,
|
|
80
|
+
// Passing some dummy context as the context isn't needed since importerFile is already resolved and absolute
|
|
81
|
+
importMetaUrl, { doNotHandleFileExtension: true });
|
|
82
|
+
if (res.hasFailed)
|
|
83
|
+
throw res.err;
|
|
84
|
+
assert(res.importedFile === importedFile);
|
|
85
|
+
}
|
|
86
|
+
return importedFile;
|
|
63
87
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
cwd = cwd.slice(prefix.length);
|
|
70
|
-
cwd = path.posix.dirname(cwd);
|
|
88
|
+
function getExtraPathsForNpmPackageImport({ importPath, userRootDir }) {
|
|
89
|
+
if (
|
|
90
|
+
// Ideally we'd set `paths` only for npm packages, but unfortunately we cannot always disambiguate between npm package imports and path aliases.
|
|
91
|
+
!isImportPathNpmPackageOrPathAlias(importPath)) {
|
|
92
|
+
return undefined;
|
|
71
93
|
}
|
|
72
|
-
|
|
73
|
-
|
|
94
|
+
const paths = [
|
|
95
|
+
// Workaround for monorepo resolve issue: https://github.com/vikejs/vike-react/pull/161/commits/dbaa6643e78015ac2797c237552800fef29b72a7
|
|
96
|
+
userRootDir,
|
|
97
|
+
// I can't think of a use case where this would be needed, but let's add it to be extra safe
|
|
98
|
+
toDirPath(importMetaUrl)
|
|
99
|
+
];
|
|
100
|
+
return paths;
|
|
74
101
|
}
|
|
75
102
|
function removeFileExtention(importPath) {
|
|
76
103
|
// Skip for Bun: https://github.com/vikejs/vike/issues/2204
|
|
@@ -88,7 +115,7 @@ function removeFileExtention(importPath) {
|
|
|
88
115
|
}
|
|
89
116
|
return importPath;
|
|
90
117
|
}
|
|
91
|
-
function addFileExtensionsToRequireResolve() {
|
|
118
|
+
function addFileExtensionsToRequireResolve(require_) {
|
|
92
119
|
const added = [];
|
|
93
120
|
scriptFileExtensionList.forEach((ext) => {
|
|
94
121
|
assert(!ext.includes('.'));
|
|
@@ -98,10 +125,42 @@ function addFileExtensionsToRequireResolve() {
|
|
|
98
125
|
added.push(ext);
|
|
99
126
|
}
|
|
100
127
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return
|
|
128
|
+
}
|
|
129
|
+
function getVikeNodeModulesRoot() {
|
|
130
|
+
// [RELATIVE_PATH_FROM_DIST] Current file: vike/dist/esm/utils/requireResolve.js
|
|
131
|
+
assert(importMetaUrl.includes('/dist/esm/') || importMetaUrl.includes('/dist/cjs/'));
|
|
132
|
+
const vikeNodeModulesRoot = path.posix.join(removeFilePrefix(importMetaUrl), '../../../../');
|
|
133
|
+
return vikeNodeModulesRoot;
|
|
134
|
+
}
|
|
135
|
+
function toDirPath(filePath) {
|
|
136
|
+
return path.posix.dirname(removeFilePrefix(filePath));
|
|
137
|
+
}
|
|
138
|
+
function getFakeFilePath(dirPath) {
|
|
139
|
+
assertPosixPath(dirPath);
|
|
140
|
+
assert(!dirPath.startsWith('file')); // The file:// prefix is bogus with path.join
|
|
141
|
+
const filePath = path.posix.join(dirPath, 'fakeFileForNodeResolve.js');
|
|
142
|
+
return filePath;
|
|
143
|
+
}
|
|
144
|
+
function addFilePrefix(filePath) {
|
|
145
|
+
const filePrefix = getFilePrefix();
|
|
146
|
+
if (!filePath.startsWith(filePrefix)) {
|
|
147
|
+
assert(!filePath.startsWith('file'));
|
|
148
|
+
filePath = filePrefix + filePath;
|
|
149
|
+
}
|
|
150
|
+
assert(filePath.startsWith(filePrefix));
|
|
151
|
+
return filePath;
|
|
152
|
+
}
|
|
153
|
+
function removeFilePrefix(filePath) {
|
|
154
|
+
const filePrefix = getFilePrefix();
|
|
155
|
+
if (filePath.startsWith(filePrefix)) {
|
|
156
|
+
filePath = filePath.slice(filePrefix.length);
|
|
157
|
+
}
|
|
158
|
+
assert(!filePath.startsWith('file'));
|
|
159
|
+
return filePath;
|
|
160
|
+
}
|
|
161
|
+
function getFilePrefix() {
|
|
162
|
+
let prefix = 'file://';
|
|
163
|
+
if (process.platform === 'win32')
|
|
164
|
+
prefix += '/';
|
|
165
|
+
return prefix;
|
|
107
166
|
}
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export { isNpmPackageImport };
|
|
2
|
-
export { isNpmPackageImport_unreliable };
|
|
3
|
-
export { assertIsNpmPackageImport };
|
|
4
|
-
export { isValidPathAlias };
|
|
5
|
-
export { parse };
|
|
6
|
-
export { isDistinguishable };
|
|
7
|
-
declare function isNpmPackageImport(str: string, { cannotBePathAlias }: {
|
|
8
|
-
cannotBePathAlias: true;
|
|
9
|
-
}): boolean;
|
|
10
|
-
declare function isNpmPackageImport_unreliable(str: string): boolean;
|
|
11
|
-
declare function assertIsNpmPackageImport(str: string): void;
|
|
12
|
-
declare function isValidPathAlias(alias: string): boolean;
|
|
13
|
-
declare function isDistinguishable(alias: string): boolean;
|
|
14
|
-
declare function parse(str: string | undefined): null | {
|
|
15
|
-
pkgName: string;
|
|
16
|
-
importPath: null | string;
|
|
17
|
-
};
|