vike 0.4.254 → 0.4.255
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/node/vite/plugins/build/pluginBuildConfig.js +2 -2
- package/dist/node/vite/plugins/pluginCommon/assertResolveAlias.js +2 -2
- package/dist/node/vite/plugins/pluginDev/optimizeDeps.js +2 -2
- package/dist/node/vite/plugins/pluginStripPointerImportAttribute.js +3 -3
- package/dist/node/vite/shared/getClientEntrySrcDev.js +2 -2
- package/dist/node/vite/shared/getFilePath.js +3 -3
- package/dist/node/vite/shared/resolveVikeConfigInternal/pointerImports.d.ts +0 -2
- package/dist/node/vite/shared/resolveVikeConfigInternal/pointerImports.js +16 -6
- package/dist/node/vite/shared/resolveVikeConfigInternal/resolvePointerImport.js +2 -2
- package/dist/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +16 -34
- package/dist/server/runtime/renderPageServer/getPageAssets/getManifestEntry.js +2 -2
- package/dist/server/runtime/renderPageServer/getPageAssets/retrievePageAssetsProd.js +2 -2
- package/dist/shared-server-client/getPageFiles/fileTypes.js +1 -1
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/dist/utils/isImportPath.js +2 -2
- package/dist/utils/isScriptFile.d.ts +2 -0
- package/dist/utils/isScriptFile.js +4 -0
- package/dist/utils/parseNpmPackage.d.ts +8 -8
- package/dist/utils/parseNpmPackage.js +13 -13
- package/dist/utils/requireResolve.js +3 -3
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ export { analyzeClientEntries };
|
|
|
4
4
|
import { assert, setAssertOnBeforeLog, assertUsage } from '../../../../utils/assert.js';
|
|
5
5
|
import { onSetupBuild } from '../../../../utils/assertSetup.js';
|
|
6
6
|
import { injectRollupInputs, normalizeRollupInput } from '../../../../utils/injectRollupInputs.js';
|
|
7
|
-
import {
|
|
7
|
+
import { assertImportIsNpmPackage } from '../../../../utils/parseNpmPackage.js';
|
|
8
8
|
import { removeFileExtension } from '../../../../utils/removeFileExtension.js';
|
|
9
9
|
import { requireResolveDistFile } from '../../../../utils/requireResolve.js';
|
|
10
10
|
import { unique } from '../../../../utils/unique.js';
|
|
@@ -154,7 +154,7 @@ async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
|
154
154
|
}
|
|
155
155
|
function getEntryFromClientEntry(clientEntry, config, addExtractAssetsQuery) {
|
|
156
156
|
if (!clientEntry.startsWith('/')) {
|
|
157
|
-
|
|
157
|
+
assertImportIsNpmPackage(clientEntry);
|
|
158
158
|
const entryTarget = clientEntry;
|
|
159
159
|
const entryName = prependEntriesDir(clientEntry);
|
|
160
160
|
return { entryName, entryTarget };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { assertResolveAlias };
|
|
2
2
|
import { assert, assertUsage, assertWarning } from '../../../../utils/assert.js';
|
|
3
3
|
import { isArray } from '../../../../utils/isArray.js';
|
|
4
|
-
import {
|
|
4
|
+
import { isPathAliasRecommendation } from '../../../../utils/parseNpmPackage.js';
|
|
5
5
|
import pc from '@brillout/picocolors';
|
|
6
6
|
import '../../assertEnvVite.js';
|
|
7
7
|
// Recommend users to avoid un-distinguishable path aliases.
|
|
@@ -62,7 +62,7 @@ function assertResolveAlias(config) {
|
|
|
62
62
|
// - resolveOptimizeDeps()
|
|
63
63
|
// - extractAssets
|
|
64
64
|
// - in general: using un-distinguishable path aliases is asking for trouble
|
|
65
|
-
if (!
|
|
65
|
+
if (!isPathAliasRecommendation(find)) {
|
|
66
66
|
if (find.startsWith('@')) {
|
|
67
67
|
const msg = `${errPrefix} defines an invalid resolve.alias ${deprecation}: a path alias cannot start with ${pc.cyan('@')}, ${errSuffix1}`;
|
|
68
68
|
assertWarning(false, msg, { onlyOnce: true });
|
|
@@ -5,7 +5,7 @@ import { assert } from '../../../../utils/assert.js';
|
|
|
5
5
|
import { createDebug } from '../../../../utils/debug.js';
|
|
6
6
|
import { isArray } from '../../../../utils/isArray.js';
|
|
7
7
|
import { isFilePathAbsoluteFilesystem } from '../../../../utils/isFilePathAbsoluteFilesystem.js';
|
|
8
|
-
import {
|
|
8
|
+
import { assertImportIsNpmPackage, getNpmPackageName } from '../../../../utils/parseNpmPackage.js';
|
|
9
9
|
import { requireResolveOptional } from '../../../../utils/requireResolve.js';
|
|
10
10
|
import { isVirtualFileId } from '../../../../utils/virtualFileId.js';
|
|
11
11
|
import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
|
|
@@ -146,7 +146,7 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
146
146
|
// optimizeDeps.include expects npm packages
|
|
147
147
|
assert(!e.startsWith('/'));
|
|
148
148
|
// Shouldn't be a path alias, as path aliases would need to be added to optimizeDeps.entries instead of optimizeDeps.include
|
|
149
|
-
|
|
149
|
+
assertImportIsNpmPackage(e);
|
|
150
150
|
if (isExcluded(e, isForClientSide, definedAt))
|
|
151
151
|
return;
|
|
152
152
|
if (isForClientSide) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { pluginStripPointerImportAttribute };
|
|
2
2
|
import { getMagicString } from '../shared/getMagicString.js';
|
|
3
3
|
import '../assertEnvVite.js';
|
|
4
|
-
// Match `with { type: 'vike
|
|
5
|
-
const runtimeAttrRE = /\bwith\s*\{\s*type\s*:\s*['"]vike
|
|
4
|
+
// Match `with { type: 'vike:pointer' }` (with optional whitespace variations)
|
|
5
|
+
const runtimeAttrRE = /\bwith\s*\{\s*type\s*:\s*['"]vike:pointer['"]\s*\}/g;
|
|
6
6
|
function pluginStripPointerImportAttribute() {
|
|
7
7
|
return [
|
|
8
8
|
{
|
|
@@ -10,7 +10,7 @@ function pluginStripPointerImportAttribute() {
|
|
|
10
10
|
transform: {
|
|
11
11
|
filter: {
|
|
12
12
|
code: {
|
|
13
|
-
include: 'vike
|
|
13
|
+
include: 'vike:pointer',
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
handler(code, id) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getClientEntrySrcDev };
|
|
2
2
|
import { assertIsNotProductionRuntime } from '../../../utils/assertSetup.js';
|
|
3
|
-
import {
|
|
3
|
+
import { assertImportIsNpmPackage } from '../../../utils/parseNpmPackage.js';
|
|
4
4
|
import { toPosixPath, pathJoin } from '../../../utils/path.js';
|
|
5
5
|
import { requireResolveNpmPackage, requireResolveDistFile } from '../../../utils/requireResolve.js';
|
|
6
6
|
import { assert } from '../../../utils/assert.js';
|
|
@@ -32,7 +32,7 @@ function getClientEntrySrcDev(clientEntry, viteDevServer) {
|
|
|
32
32
|
filePath = requireResolveDistFile(`dist/${clientEntry.replace('@@vike/dist/', '')}`);
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
35
|
-
|
|
35
|
+
assertImportIsNpmPackage(clientEntry);
|
|
36
36
|
filePath = requireResolveNpmPackage({ importPathNpmPackage: clientEntry, userRootDir });
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -7,7 +7,7 @@ export { cleanFilePathUnknown };
|
|
|
7
7
|
export { assertModuleId };
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import { assertFilePathAbsoluteFilesystem } from '../../../utils/isFilePathAbsoluteFilesystem.js';
|
|
10
|
-
import {
|
|
10
|
+
import { assertImportIsNpmPackage } from '../../../utils/parseNpmPackage.js';
|
|
11
11
|
import { toPosixPath } from '../../../utils/path.js';
|
|
12
12
|
import { assert } from '../../../utils/assert.js';
|
|
13
13
|
import { assertPosixPath } from '../../../utils/path.js';
|
|
@@ -43,7 +43,7 @@ function getComputedProps(args) {
|
|
|
43
43
|
const importPathAbsolute = args.importPathAbsolute ?? null;
|
|
44
44
|
const { filePathAbsoluteUserRootDir } = args;
|
|
45
45
|
if (importPathAbsolute)
|
|
46
|
-
|
|
46
|
+
assertImportIsNpmPackage(importPathAbsolute);
|
|
47
47
|
return {
|
|
48
48
|
importPathAbsolute,
|
|
49
49
|
filePathAbsoluteUserRootDir,
|
|
@@ -57,7 +57,7 @@ function getComputedProps(args) {
|
|
|
57
57
|
}
|
|
58
58
|
function getComputedPropsImportPathAbsolute(args) {
|
|
59
59
|
const { importPathAbsolute } = args;
|
|
60
|
-
|
|
60
|
+
assertImportIsNpmPackage(importPathAbsolute);
|
|
61
61
|
return {
|
|
62
62
|
filePathAbsoluteUserRootDir: null,
|
|
63
63
|
importPathAbsolute,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { transformPointerImports };
|
|
2
2
|
export { parsePointerImportData };
|
|
3
|
-
export { isPointerImportData };
|
|
4
3
|
export { assertPointerImportPath };
|
|
5
4
|
export type { PointerImportData };
|
|
6
5
|
import '../../assertEnvVite.js';
|
|
@@ -23,7 +22,6 @@ type PointerImportData = {
|
|
|
23
22
|
importString: string;
|
|
24
23
|
importStringWasGenerated: boolean;
|
|
25
24
|
};
|
|
26
|
-
declare function isPointerImportData(str: string): boolean;
|
|
27
25
|
declare function parsePointerImportData(importString: string): null | PointerImportData;
|
|
28
26
|
declare function assertPointerImportPath(importPath: string): boolean;
|
|
29
27
|
declare module 'estree' {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { transformPointerImports };
|
|
2
2
|
export { parsePointerImportData };
|
|
3
|
-
export { isPointerImportData };
|
|
4
3
|
export { assertPointerImportPath };
|
|
5
4
|
// Playground: https://github.com/brillout/acorn-playground
|
|
6
5
|
// Notes about `with { type: 'pointer' }`
|
|
@@ -30,6 +29,10 @@ function transformPointerImports(code, filePathToShowToUser2, pointerImports,
|
|
|
30
29
|
// For ./transformPointerImports.spec.ts
|
|
31
30
|
skipWarnings) {
|
|
32
31
|
const spliceOperations = [];
|
|
32
|
+
// Collect all const declarations to prepend at the top, so that they are
|
|
33
|
+
// available before any code runs (import declarations are hoisted but const
|
|
34
|
+
// is not, so we must place them at the top to avoid TDZ errors).
|
|
35
|
+
const constDeclarations = [];
|
|
33
36
|
// Performance trick
|
|
34
37
|
if (!code.includes('import'))
|
|
35
38
|
return null;
|
|
@@ -78,7 +81,7 @@ skipWarnings) {
|
|
|
78
81
|
assertWarning(false, errMsg, { onlyOnce: true });
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
|
-
let
|
|
84
|
+
let constDeclaration = '';
|
|
82
85
|
node.specifiers.forEach((specifier) => {
|
|
83
86
|
assert(specifier.type === 'ImportSpecifier' ||
|
|
84
87
|
specifier.type === 'ImportDefaultSpecifier' ||
|
|
@@ -97,16 +100,23 @@ skipWarnings) {
|
|
|
97
100
|
return importLocalName;
|
|
98
101
|
})();
|
|
99
102
|
const importString = serializePointerImportData({ importPath, exportName, importStringWasGenerated: true });
|
|
100
|
-
|
|
103
|
+
constDeclaration += `const ${importLocalName} = '${importString}';`;
|
|
101
104
|
});
|
|
105
|
+
if (constDeclaration)
|
|
106
|
+
constDeclarations.push(constDeclaration);
|
|
107
|
+
// Replace the import with blank lines to preserve source map line numbers.
|
|
102
108
|
spliceOperations.push({
|
|
103
109
|
start,
|
|
104
110
|
end,
|
|
105
|
-
replacement,
|
|
111
|
+
replacement: '\n'.repeat(importStatementCode.split('\n').length - 1),
|
|
106
112
|
});
|
|
107
113
|
});
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
if (constDeclarations.length === 0 && spliceOperations.length === 0)
|
|
115
|
+
return null;
|
|
116
|
+
const codeWithImportsRemoved = spliceMany(code, spliceOperations);
|
|
117
|
+
if (constDeclarations.length === 0)
|
|
118
|
+
return codeWithImportsRemoved;
|
|
119
|
+
return constDeclarations.join('') + '\n' + codeWithImportsRemoved;
|
|
110
120
|
}
|
|
111
121
|
function getImports(code) {
|
|
112
122
|
const result = parseSync(code, {
|
|
@@ -4,7 +4,7 @@ import pc from '@brillout/picocolors';
|
|
|
4
4
|
import { assert, assertUsage } from '../../../../utils/assert.js';
|
|
5
5
|
import { isFilePathAbsolute } from '../../../../utils/isFilePathAbsoluteFilesystem.js';
|
|
6
6
|
import { isImportPathRelative } from '../../../../utils/isImportPath.js';
|
|
7
|
-
import {
|
|
7
|
+
import { isImportNpmPackageOrPathAlias } from '../../../../utils/parseNpmPackage.js';
|
|
8
8
|
import { assertPosixPath } from '../../../../utils/path.js';
|
|
9
9
|
import { requireResolveOptional } from '../../../../utils/requireResolve.js';
|
|
10
10
|
import { assertPointerImportPath, parsePointerImportData } from './pointerImports.js';
|
|
@@ -50,7 +50,7 @@ function resolvePointerImportData(pointerImportData, importerFilePath, userRootD
|
|
|
50
50
|
filePath = getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir });
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
assert(
|
|
53
|
+
assert(isImportNpmPackageOrPathAlias(importPath));
|
|
54
54
|
const importPathAbsolute = importPath;
|
|
55
55
|
if (filePathAbsoluteFilesystem) {
|
|
56
56
|
filePath = getFilePathResolved({
|
|
@@ -15,9 +15,9 @@ import { genPromise } from '../../../../utils/genPromise.js';
|
|
|
15
15
|
import { assertFilePathAbsoluteFilesystem } from '../../../../utils/isFilePathAbsoluteFilesystem.js';
|
|
16
16
|
import { isImportPathRelative } from '../../../../utils/isImportPath.js';
|
|
17
17
|
import { isObject } from '../../../../utils/isObject.js';
|
|
18
|
-
import { isPlainScriptFile } from '../../../../utils/isScriptFile.js';
|
|
18
|
+
import { isPlainJavaScriptFile, isPlainScriptFile } from '../../../../utils/isScriptFile.js';
|
|
19
19
|
import { isVitest } from '../../../../utils/isVitest.js';
|
|
20
|
-
import {
|
|
20
|
+
import { assertImportIsNpmPackage, isImportNpmPackageOrPathAlias } from '../../../../utils/parseNpmPackage.js';
|
|
21
21
|
import { assertPosixPath, toPosixPath } from '../../../../utils/path.js';
|
|
22
22
|
import { requireResolveOptionalDir } from '../../../../utils/requireResolve.js';
|
|
23
23
|
import { transformPointerImports } from './pointerImports.js';
|
|
@@ -179,10 +179,10 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
179
179
|
const importPathOriginal = args.path;
|
|
180
180
|
// Esbuild resolves path aliases.
|
|
181
181
|
// - Enabling us to use:
|
|
182
|
-
// -
|
|
183
|
-
// -
|
|
182
|
+
// - assertImportIsNpmPackage()
|
|
183
|
+
// - isImportNpmPackage(str, { cannotBePathAlias: true })
|
|
184
184
|
assertFilePathAbsoluteFilesystem(importPathResolved);
|
|
185
|
-
// Should
|
|
185
|
+
// Should we remove this? See comment below.
|
|
186
186
|
const isVikeExtensionImport = (path.startsWith('vike-') && path.endsWith('/config')) || importPathResolved.endsWith('+config.js');
|
|
187
187
|
const isPointerImport = transformImports === 'all' ||
|
|
188
188
|
// .jsx, .vue, .svg, ... => obviously not config code => pointer import
|
|
@@ -193,32 +193,20 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
193
193
|
// - vike@0.4.162 started soft-requiring Vike extensions to set the name config.
|
|
194
194
|
// - In practice, it seems like it requires some (non-trivial?) refactoring.
|
|
195
195
|
isVikeExtensionImport ||
|
|
196
|
-
args.with?.['type'] === 'vike
|
|
196
|
+
args.with?.['type'] === 'vike:pointer';
|
|
197
197
|
assertPosixPath(importPathResolved);
|
|
198
|
-
//
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
// Linked npm packages
|
|
206
|
-
if (
|
|
207
|
-
// Assuming path aliases usually resolve inside `userRootDir`.
|
|
208
|
-
// - This isn't always the case: https://github.com/vikejs/vike/issues/2326
|
|
209
|
-
!importPathResolved.startsWith(userRootDir) &&
|
|
210
|
-
// False positive if `importPathOriginal` is a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir` => we then we wrongfully assume that `importPathOriginal` is an npm package import.
|
|
211
|
-
isImportPathNpmPackageOrPathAlias(importPathOriginal)) {
|
|
212
|
-
return true;
|
|
213
|
-
}
|
|
214
|
-
return false;
|
|
215
|
-
})();
|
|
198
|
+
// False positive if `importPathOriginal` is a path alias that a) looks like an npm package import and b) resolves outside of `userRootDir` => we then we wrongfully assume that `importPathOriginal` is an npm package import.
|
|
199
|
+
// - For example: https://github.com/vikejs/vike/issues/2326
|
|
200
|
+
const isMostLikelyNpmPkgImport = isImportNpmPackageOrPathAlias(importPathOriginal) &&
|
|
201
|
+
(importPathResolved.includes('/node_modules/') ||
|
|
202
|
+
// Linked npm package
|
|
203
|
+
!importPathResolved.startsWith(userRootDir));
|
|
216
204
|
const isExternal = isPointerImport ||
|
|
217
205
|
// Performance: npm package imports can be externalized. (We could as well let esbuild transpile /node_modules/ code but it's useless as /node_modules/ code is already built. It would unnecessarily slow down transpilation.)
|
|
218
|
-
|
|
206
|
+
(isMostLikelyNpmPkgImport && isPlainJavaScriptFile(importPathResolved));
|
|
219
207
|
if (!isExternal) {
|
|
220
208
|
// User-land config code (i.e. not runtime code) => let esbuild transpile it
|
|
221
|
-
assert(!isPointerImport
|
|
209
|
+
assert(!isPointerImport);
|
|
222
210
|
if (debug.isActivated)
|
|
223
211
|
debug('onResolve() [non-external]', { args, resolved, isPointerImport, isExternal });
|
|
224
212
|
return resolved;
|
|
@@ -236,7 +224,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
236
224
|
filePathAbsoluteFilesystem: importPathResolved,
|
|
237
225
|
userRootDir,
|
|
238
226
|
});
|
|
239
|
-
if (filePathAbsoluteUserRootDir && !
|
|
227
|
+
if (filePathAbsoluteUserRootDir && !isMostLikelyNpmPkgImport) {
|
|
240
228
|
// `importPathOriginal` is most likely a path alias.
|
|
241
229
|
// - We have to use esbuild's path alias resolution, because:
|
|
242
230
|
// - Vike doesn't resolve path aliases at all.
|
|
@@ -246,19 +234,13 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esb
|
|
|
246
234
|
}
|
|
247
235
|
else {
|
|
248
236
|
// `importPathOriginal` is most likely an npm package import.
|
|
249
|
-
|
|
237
|
+
assertImportIsNpmPackage(importPathOriginal);
|
|
250
238
|
// For improved error messages, let the resolution be handled by Vike or Node.js.
|
|
251
239
|
importPathTranspiled = importPathOriginal;
|
|
252
240
|
}
|
|
253
241
|
}
|
|
254
242
|
if (debug.isActivated)
|
|
255
243
|
debug('onResolve() [external]', { args, resolved, importPathTranspiled, isPointerImport, isExternal });
|
|
256
|
-
assert(isExternal);
|
|
257
|
-
assert(
|
|
258
|
-
// Import of runtime code => handled by Vike
|
|
259
|
-
isPointerImport ||
|
|
260
|
-
// Import of config code => loaded by Node.js at build-time
|
|
261
|
-
isNpmPkgImport);
|
|
262
244
|
pointerImports[importPathTranspiled] = isPointerImport;
|
|
263
245
|
return { external: true, path: importPathTranspiled };
|
|
264
246
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getManifestEntry };
|
|
2
2
|
import { slice } from '../../../../utils/slice.js';
|
|
3
|
-
import {
|
|
3
|
+
import { assertImportIsNpmPackage } from '../../../../utils/parseNpmPackage.js';
|
|
4
4
|
import { assert } from '../../../../utils/assert.js';
|
|
5
5
|
import { parseVirtualFileId } from '../../../../shared-server-node/virtualFileId.js';
|
|
6
6
|
import { prependEntriesDir } from '../../../../shared-server-node/prependEntriesDir.js';
|
|
@@ -44,7 +44,7 @@ function getManifestEntry(id, assetsManifest) {
|
|
|
44
44
|
return { manifestEntry, manifestKey };
|
|
45
45
|
}
|
|
46
46
|
// npm package import
|
|
47
|
-
|
|
47
|
+
assertImportIsNpmPackage(id);
|
|
48
48
|
const found = Object.entries(assetsManifest).find(([, e]) => e.name === prependEntriesDir(id));
|
|
49
49
|
assert(found);
|
|
50
50
|
const [manifestKey, manifestEntry] = found;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { retrievePageAssetsProd };
|
|
2
2
|
export { resolveIncludeAssetsImportedByServer };
|
|
3
|
-
import {
|
|
3
|
+
import { isImportNpmPackage } from '../../../../utils/parseNpmPackage.js';
|
|
4
4
|
import { assert } from '../../../../utils/assert.js';
|
|
5
5
|
import { getManifestEntry } from './getManifestEntry.js';
|
|
6
6
|
import { extractAssetsAddQuery } from '../../../../shared-server-node/extractAssetsQuery.js';
|
|
@@ -30,7 +30,7 @@ function getAssetsUrl(clientDependencies, assetsManifest, config) {
|
|
|
30
30
|
onlyAssets &&
|
|
31
31
|
id.includes('.page.server.') &&
|
|
32
32
|
// We assume that all npm packages have already built their files: bundlers (Rollup, esbuild, tsup, ...) extract the CSS out of JavaScript => we can assume JavaScript to not import any CSS/assets.
|
|
33
|
-
!
|
|
33
|
+
!isImportNpmPackage(id, {
|
|
34
34
|
// I presume Vite already resolves path aliases when Vite sets the module's id
|
|
35
35
|
cannotBePathAlias: true,
|
|
36
36
|
})) {
|
|
@@ -22,7 +22,7 @@ function determineFileType(filePath) {
|
|
|
22
22
|
const isCSS = filePath.endsWith('.css');
|
|
23
23
|
if (isCSS) {
|
|
24
24
|
/* This assert() is skipped to reduce client-side bundle size
|
|
25
|
-
assert(
|
|
25
|
+
assert(isImportNpmPackage(filePath), filePath) // `.css` page files are only supported for npm packages
|
|
26
26
|
*/
|
|
27
27
|
return '.css';
|
|
28
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.255";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.255';
|
|
@@ -2,9 +2,9 @@ export { isImportPath };
|
|
|
2
2
|
export { isImportPathRelative };
|
|
3
3
|
import { assertPosixPath } from './path.js';
|
|
4
4
|
import { assert } from './assert.js';
|
|
5
|
-
import {
|
|
5
|
+
import { isImportNpmPackageOrPathAlias } from './parseNpmPackage.js';
|
|
6
6
|
function isImportPath(importPath) {
|
|
7
|
-
return isImportPathRelative(importPath) ||
|
|
7
|
+
return isImportPathRelative(importPath) || isImportNpmPackageOrPathAlias(importPath);
|
|
8
8
|
}
|
|
9
9
|
// See also `import { pathIsRelative } from './path'`
|
|
10
10
|
function isImportPathRelative(importPath) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { isScriptFile };
|
|
2
2
|
export { isPlainScriptFile };
|
|
3
|
+
export { isPlainJavaScriptFile };
|
|
3
4
|
export { isTemplateFile };
|
|
4
5
|
export { scriptFileExtensionList };
|
|
5
6
|
export { scriptFileExtensionPattern };
|
|
@@ -7,4 +8,5 @@ declare const scriptFileExtensionList: readonly ["js", "cjs", "mjs", "ts", "cts"
|
|
|
7
8
|
declare const scriptFileExtensionPattern: string;
|
|
8
9
|
declare function isScriptFile(filePath: string): boolean;
|
|
9
10
|
declare function isPlainScriptFile(filePath: string): boolean;
|
|
11
|
+
declare function isPlainJavaScriptFile(filePath: string): boolean;
|
|
10
12
|
declare function isTemplateFile(filePath: string): boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { isScriptFile };
|
|
2
2
|
export { isPlainScriptFile };
|
|
3
|
+
export { isPlainJavaScriptFile };
|
|
3
4
|
export { isTemplateFile };
|
|
4
5
|
export { scriptFileExtensionList };
|
|
5
6
|
export { scriptFileExtensionPattern };
|
|
@@ -59,6 +60,9 @@ function isScriptFile(filePath) {
|
|
|
59
60
|
function isPlainScriptFile(filePath) {
|
|
60
61
|
return extJsOrTs.some((ext) => filePath.endsWith('.' + ext));
|
|
61
62
|
}
|
|
63
|
+
function isPlainJavaScriptFile(filePath) {
|
|
64
|
+
return extJs.some((ext) => filePath.endsWith('.' + ext));
|
|
65
|
+
}
|
|
62
66
|
function isTemplateFile(filePath) {
|
|
63
67
|
return extTemplates.some((ext) => filePath.endsWith('.' + ext));
|
|
64
68
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { isImportNpmPackage };
|
|
2
|
+
export { isImportNpmPackageOrPathAlias };
|
|
3
|
+
export { assertImportIsNpmPackage };
|
|
4
|
+
export { isPathAliasRecommendation };
|
|
5
5
|
export { getNpmPackageName };
|
|
6
6
|
export { parseNpmPackage };
|
|
7
7
|
export { isDistinguishable };
|
|
8
8
|
declare function getNpmPackageName(str: string): null | string;
|
|
9
|
-
declare function
|
|
9
|
+
declare function isImportNpmPackage(str: string, { cannotBePathAlias }: {
|
|
10
10
|
cannotBePathAlias: true;
|
|
11
11
|
}): boolean;
|
|
12
|
-
declare function
|
|
13
|
-
declare function
|
|
14
|
-
declare function
|
|
12
|
+
declare function isImportNpmPackageOrPathAlias(str: string): boolean;
|
|
13
|
+
declare function assertImportIsNpmPackage(str: string): void;
|
|
14
|
+
declare function isPathAliasRecommendation(alias: string): boolean;
|
|
15
15
|
declare function isDistinguishable(alias: string): boolean;
|
|
16
16
|
declare function parseNpmPackage(str: string | undefined): null | {
|
|
17
17
|
pkgName: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { isImportNpmPackage };
|
|
2
|
+
export { isImportNpmPackageOrPathAlias };
|
|
3
|
+
export { assertImportIsNpmPackage };
|
|
4
|
+
export { isPathAliasRecommendation };
|
|
5
5
|
export { getNpmPackageName };
|
|
6
6
|
// For ./isNpmPackage.spec.ts
|
|
7
7
|
export { parseNpmPackage };
|
|
@@ -16,7 +16,7 @@ function getNpmPackageName(str) {
|
|
|
16
16
|
return res.pkgName;
|
|
17
17
|
}
|
|
18
18
|
/* Currently not used
|
|
19
|
-
export function
|
|
19
|
+
export function isValidNpmPackageName(str: string | undefined): boolean {
|
|
20
20
|
const res = parseNpmPackage(str)
|
|
21
21
|
return res !== null && res.importPath === null
|
|
22
22
|
}
|
|
@@ -28,22 +28,22 @@ export function getNpmPackageImportPath(str: string): null | string {
|
|
|
28
28
|
return res.importPath
|
|
29
29
|
}
|
|
30
30
|
//*/
|
|
31
|
-
function
|
|
31
|
+
function isImportNpmPackage(str, { cannotBePathAlias }) {
|
|
32
32
|
assert(cannotBePathAlias);
|
|
33
|
-
return
|
|
33
|
+
return isImportNpmPackageOrPathAlias(str);
|
|
34
34
|
}
|
|
35
35
|
// We cannot distinguish path aliases that look like npm package imports
|
|
36
|
-
function
|
|
36
|
+
function isImportNpmPackageOrPathAlias(str) {
|
|
37
37
|
const res = parseNpmPackage(str);
|
|
38
38
|
return res !== null;
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
assert(
|
|
42
|
-
// If `str` is a path alias that looks like an npm package =>
|
|
40
|
+
function assertImportIsNpmPackage(str) {
|
|
41
|
+
assert(isImportNpmPackage(str, {
|
|
42
|
+
// If `str` is a path alias that looks like an npm package => assertImportIsNpmPackage() is erroneous but that's okay because the assertion will eventually fail for some other user using a disambiguated path alias.
|
|
43
43
|
cannotBePathAlias: true,
|
|
44
44
|
}), str);
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function isPathAliasRecommendation(alias) {
|
|
47
47
|
// Cannot be distinguished from npm package names
|
|
48
48
|
if (!isDistinguishable(alias))
|
|
49
49
|
return false;
|
|
@@ -64,7 +64,7 @@ function isDistinguishable(alias) {
|
|
|
64
64
|
parseNpmPackage(`${alias}/fake-path`) === null &&
|
|
65
65
|
parseNpmPackage(`${alias}fake/deep/path`) === null &&
|
|
66
66
|
parseNpmPackage(`${alias}/fake/deep/path`) === null &&
|
|
67
|
-
// See note about '-' in ./
|
|
67
|
+
// See note about '-' in ./parseNpmPackage.spec.ts
|
|
68
68
|
// ```ts
|
|
69
69
|
// expect(parseNpmPackage('-')).toBe(null) // actually wrong: https://www.npmjs.com/package/-
|
|
70
70
|
// ```
|
|
@@ -10,7 +10,7 @@ import { assertPosixPath, toPosixPath } from './path.js';
|
|
|
10
10
|
import { scriptFileExtensionList } from './isScriptFile.js';
|
|
11
11
|
import { createRequire } from 'node:module';
|
|
12
12
|
import path from 'node:path';
|
|
13
|
-
import {
|
|
13
|
+
import { assertImportIsNpmPackage, isImportNpmPackageOrPathAlias } from './parseNpmPackage.js';
|
|
14
14
|
import { isNotNullish } from './isNullish.js';
|
|
15
15
|
import { createDebug } from './debug.js';
|
|
16
16
|
const importMetaUrl = import.meta.url;
|
|
@@ -96,7 +96,7 @@ function requireResolveOptionalDir({ importPath, importerDir, userRootDir, }) {
|
|
|
96
96
|
return res.importPathResolvedFilePath;
|
|
97
97
|
}
|
|
98
98
|
function requireResolveNpmPackage({ importPathNpmPackage, userRootDir, }) {
|
|
99
|
-
|
|
99
|
+
assertImportIsNpmPackage(importPathNpmPackage);
|
|
100
100
|
const importerFilePath = getFakeImporterFile(userRootDir);
|
|
101
101
|
const res = requireResolve_(importPathNpmPackage, importerFilePath, userRootDir);
|
|
102
102
|
if (res.hasFailed)
|
|
@@ -121,7 +121,7 @@ function requireResolveDistFile(distFile) {
|
|
|
121
121
|
}
|
|
122
122
|
function addExtraContextForNpmPackageImport(contexts, importPath, userRootDir) {
|
|
123
123
|
// We should add extra context only for npm packages, but unfortunately we cannot always disambiguate between npm package imports and path aliases.
|
|
124
|
-
if (!
|
|
124
|
+
if (!isImportNpmPackageOrPathAlias(importPath))
|
|
125
125
|
return;
|
|
126
126
|
const userRootDirFakeFile = userRootDir && getFakeImporterFile(userRootDir);
|
|
127
127
|
[
|