vike 0.4.167-commit-cfadd0a → 0.4.168
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/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +0 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +112 -96
- package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +3 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +113 -97
- package/dist/esm/utils/assertPathIsFilesystemAbsolute.js +3 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +2 -2
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -68,7 +68,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
68
68
|
const { importPath: importPathAbsolute } = importData;
|
|
69
69
|
const filePathAbsoluteFilesystem = (0, resolveImportPath_js_1.resolveImportPath)(importData, configFilePath);
|
|
70
70
|
(0, resolveImportPath_js_1.assertImportPath)(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
71
|
-
warnUserLandExtension(importPathAbsolute, configFilePath);
|
|
72
71
|
const filePath = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteFilesystem, userRootDir, importPathAbsolute });
|
|
73
72
|
extendsConfigFiles.push(filePath);
|
|
74
73
|
});
|
|
@@ -81,13 +80,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
81
80
|
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
82
81
|
return { extendsConfigs, extendsFilePaths };
|
|
83
82
|
}
|
|
84
|
-
function warnUserLandExtension(importPath, configFilePath) {
|
|
85
|
-
// We preserve this feature because we may need it for eject
|
|
86
|
-
(0, utils_js_1.assertWarning)((0, utils_js_1.isNpmPackageImport)(importPath, {
|
|
87
|
-
// Vike config files don't support path aliases. (If they do one day, then Vike will/should be able to resolve path aliases.)
|
|
88
|
-
cannotBePathAlias: true
|
|
89
|
-
}) || importPath.includes('/node_modules/'), `${configFilePath.filePathToShowToUser} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this.`, { onlyOnce: true });
|
|
90
|
-
}
|
|
91
83
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
92
84
|
const { filePathToShowToUser } = configFilePath;
|
|
93
85
|
const configFileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(configFileExports, filePathToShowToUser);
|
|
@@ -82,98 +82,96 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
82
82
|
// Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
|
|
83
83
|
treeShaking: false,
|
|
84
84
|
minify: false,
|
|
85
|
-
metafile:
|
|
86
|
-
bundle:
|
|
85
|
+
metafile: true,
|
|
86
|
+
bundle: true
|
|
87
87
|
};
|
|
88
|
-
let pointerImports;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
setup(build) {
|
|
102
|
-
// https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
88
|
+
let pointerImports = {};
|
|
89
|
+
options.plugins = [
|
|
90
|
+
// Determine whether an import should be:
|
|
91
|
+
// - A pointer import
|
|
92
|
+
// - Externalized
|
|
93
|
+
{
|
|
94
|
+
name: 'vike-esbuild',
|
|
95
|
+
setup(build) {
|
|
96
|
+
// https://github.com/brillout/esbuild-playground
|
|
97
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
98
|
+
if (args.kind !== 'import-statement')
|
|
99
|
+
return;
|
|
100
|
+
// Avoid infinite loop: https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
103
101
|
const useEsbuildResolver = 'useEsbuildResolver';
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// - This is temporary, see comment below.
|
|
125
|
-
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
126
|
-
const isPointerImport =
|
|
102
|
+
if (args.pluginData?.[useEsbuildResolver])
|
|
103
|
+
return;
|
|
104
|
+
const { path, ...opts } = args;
|
|
105
|
+
opts.pluginData = { [useEsbuildResolver]: true };
|
|
106
|
+
const resolved = await build.resolve(path, opts);
|
|
107
|
+
if (resolved.errors.length > 0) {
|
|
108
|
+
/* We could do the following to let Node.js throw the error, but we don't because the error shown by esbuild is prettier: the Node.js error refers to the transpiled [build-f7i251e0iwnw]+config.ts.mjs file which isn't that nice, whereas esbuild refers to the source +config.ts file.
|
|
109
|
+
pointerImports[args.path] = false
|
|
110
|
+
return { external: true }
|
|
111
|
+
*/
|
|
112
|
+
// Let esbuild throw the error. (It throws a nice & pretty error.)
|
|
113
|
+
cleanEsbuildErrors(resolved.errors);
|
|
114
|
+
return resolved;
|
|
115
|
+
}
|
|
116
|
+
(0, utils_js_1.assert)(resolved.path);
|
|
117
|
+
resolved.path = (0, utils_js_1.toPosixPath)(resolved.path);
|
|
118
|
+
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
119
|
+
// - This is temporary, see comment below.
|
|
120
|
+
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
121
|
+
const isPointerImport = transformImports === 'all' ||
|
|
127
122
|
// .jsx, .vue, .svg, ... => obviously not config code
|
|
128
123
|
!(0, utils_js_1.isJavaScriptFile)(resolved.path) ||
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
name: 'vike:dependency-tracker',
|
|
156
|
-
setup(b) {
|
|
157
|
-
b.onLoad({ filter: /./ }, (args) => {
|
|
158
|
-
// We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
|
|
159
|
-
let { path } = args;
|
|
160
|
-
path = (0, utils_js_1.toPosixPath)(path);
|
|
161
|
-
getVikeConfig_js_1.vikeConfigDependencies.add(path);
|
|
162
|
-
return undefined;
|
|
163
|
-
});
|
|
164
|
-
/* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
|
|
165
|
-
* - Because onLoad() isn't call if the config dependency can't be resolved.
|
|
166
|
-
* - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
|
|
167
|
-
* ```bash
|
|
168
|
-
* mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
|
|
169
|
-
* ```
|
|
170
|
-
* - But implementing a fix is complex and isn't worth it.
|
|
171
|
-
b.onResolve(...)
|
|
172
|
-
*/
|
|
173
|
-
}
|
|
124
|
+
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a configas been set by the user or by a Vike extension).
|
|
125
|
+
// - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
126
|
+
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
127
|
+
isVikeExtensionConfigImport ||
|
|
128
|
+
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
129
|
+
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
130
|
+
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
131
|
+
resolved.errors.length > 0;
|
|
132
|
+
pointerImports[resolved.path] = isPointerImport;
|
|
133
|
+
(0, utils_js_1.assertPosixPath)(resolved.path);
|
|
134
|
+
const isExternal = isPointerImport ||
|
|
135
|
+
// Performance: npm package imports that aren't pointer imports can be externalized. For example, if Vike eventually adds support for setting Vite configs in the vike.config.js file, then the user may import a Vite plugin in his vike.config.js file. (We could as well let esbuild always transpile /node_modules/ code but it would be useless and would unnecessarily slow down transpilation.)
|
|
136
|
+
resolved.path.includes('/node_modules/');
|
|
137
|
+
if (debug.isActivated)
|
|
138
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
139
|
+
// We need esbuild to resolve path aliases so that we can use:
|
|
140
|
+
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
141
|
+
// assertIsNpmPackageImport()
|
|
142
|
+
(0, utils_js_1.assertPathIsFilesystemAbsolute)(resolved.path);
|
|
143
|
+
if (isExternal) {
|
|
144
|
+
return { external: true, path: resolved.path };
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return resolved;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
174
150
|
}
|
|
175
|
-
|
|
176
|
-
|
|
151
|
+
},
|
|
152
|
+
// Track dependencies
|
|
153
|
+
{
|
|
154
|
+
name: 'vike:dependency-tracker',
|
|
155
|
+
setup(b) {
|
|
156
|
+
b.onLoad({ filter: /./ }, (args) => {
|
|
157
|
+
// We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
|
|
158
|
+
let { path } = args;
|
|
159
|
+
path = (0, utils_js_1.toPosixPath)(path);
|
|
160
|
+
getVikeConfig_js_1.vikeConfigDependencies.add(path);
|
|
161
|
+
return undefined;
|
|
162
|
+
});
|
|
163
|
+
/* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
|
|
164
|
+
* - Because onLoad() isn't call if the config dependency can't be resolved.
|
|
165
|
+
* - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
|
|
166
|
+
* ```bash
|
|
167
|
+
* mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
|
|
168
|
+
* ```
|
|
169
|
+
* - But implementing a fix is complex and isn't worth it.
|
|
170
|
+
b.onResolve(...)
|
|
171
|
+
*/
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
];
|
|
177
175
|
let result;
|
|
178
176
|
try {
|
|
179
177
|
result = await (0, esbuild_1.build)(options);
|
|
@@ -183,15 +181,13 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
183
181
|
throw err;
|
|
184
182
|
}
|
|
185
183
|
// Track dependencies
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
});
|
|
194
|
-
}
|
|
184
|
+
(0, utils_js_1.assert)(result.metafile);
|
|
185
|
+
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
186
|
+
filePathRelative = (0, utils_js_1.toPosixPath)(filePathRelative);
|
|
187
|
+
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
188
|
+
const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathRelative);
|
|
189
|
+
getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
190
|
+
});
|
|
195
191
|
const code = result.outputFiles[0].text;
|
|
196
192
|
(0, utils_js_1.assert)(typeof code === 'string');
|
|
197
193
|
return { code, pointerImports };
|
|
@@ -316,3 +312,23 @@ function getErrIntroMsg(operation, filePath) {
|
|
|
316
312
|
].join(' ');
|
|
317
313
|
return msg;
|
|
318
314
|
}
|
|
315
|
+
function cleanEsbuildErrors(errors) {
|
|
316
|
+
errors.forEach((e) => (e.notes = e.notes.filter((note) =>
|
|
317
|
+
// Remove note:
|
|
318
|
+
// ```shell
|
|
319
|
+
// You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
|
|
320
|
+
// ```
|
|
321
|
+
//
|
|
322
|
+
// From error:
|
|
323
|
+
// ```shell
|
|
324
|
+
// ✘ [ERROR] Could not resolve "#root/renderer/onRenderHtml_typo" [plugin vike-esbuild]
|
|
325
|
+
//
|
|
326
|
+
// renderer/+config.h.js:1:29:
|
|
327
|
+
// 1 │ import { onRenderHtml } from "#root/renderer/onRenderHtml_typo"
|
|
328
|
+
// ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
329
|
+
//
|
|
330
|
+
// You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
|
|
331
|
+
//
|
|
332
|
+
// ```
|
|
333
|
+
!note.text.includes('as external to exclude it from the bundle'))));
|
|
334
|
+
}
|
|
@@ -11,11 +11,11 @@ const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
|
|
|
11
11
|
function assertPathIsFilesystemAbsolute(p) {
|
|
12
12
|
(0, filesystemPathHandling_js_1.assertPosixPath)(p);
|
|
13
13
|
(0, assert_js_1.assert)(!p.startsWith('/@fs/'));
|
|
14
|
-
if (process.platform
|
|
15
|
-
(0, assert_js_1.assert)(
|
|
14
|
+
if (process.platform !== 'win32') {
|
|
15
|
+
(0, assert_js_1.assert)(p.startsWith('/'));
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
|
-
(0, assert_js_1.assert)(
|
|
18
|
+
(0, assert_js_1.assert)(path_1.default.win32.isAbsolute(p));
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
exports.assertPathIsFilesystemAbsolute = assertPathIsFilesystemAbsolute;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PROJECT_VERSION = exports.projectInfo = void 0;
|
|
4
|
-
const PROJECT_VERSION = '0.4.
|
|
4
|
+
const PROJECT_VERSION = '0.4.168';
|
|
5
5
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { loadImportedFile };
|
|
3
3
|
export { loadValueFile };
|
|
4
4
|
export { loadConfigFile };
|
|
5
|
-
import { assert, assertUsage,
|
|
5
|
+
import { assert, assertUsage, hasProp, assertIsNotProductionRuntime } from '../../../../utils.js';
|
|
6
6
|
import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
7
7
|
import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
@@ -62,7 +62,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
62
62
|
const { importPath: importPathAbsolute } = importData;
|
|
63
63
|
const filePathAbsoluteFilesystem = resolveImportPath(importData, configFilePath);
|
|
64
64
|
assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
65
|
-
warnUserLandExtension(importPathAbsolute, configFilePath);
|
|
66
65
|
const filePath = getFilePathResolved({ filePathAbsoluteFilesystem, userRootDir, importPathAbsolute });
|
|
67
66
|
extendsConfigFiles.push(filePath);
|
|
68
67
|
});
|
|
@@ -75,13 +74,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
75
74
|
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
76
75
|
return { extendsConfigs, extendsFilePaths };
|
|
77
76
|
}
|
|
78
|
-
function warnUserLandExtension(importPath, configFilePath) {
|
|
79
|
-
// We preserve this feature because we may need it for eject
|
|
80
|
-
assertWarning(isNpmPackageImport(importPath, {
|
|
81
|
-
// Vike config files don't support path aliases. (If they do one day, then Vike will/should be able to resolve path aliases.)
|
|
82
|
-
cannotBePathAlias: true
|
|
83
|
-
}) || importPath.includes('/node_modules/'), `${configFilePath.filePathToShowToUser} uses ${pc.cyan('extends')} to inherit from ${pc.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this.`, { onlyOnce: true });
|
|
84
|
-
}
|
|
85
77
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
86
78
|
const { filePathToShowToUser } = configFilePath;
|
|
87
79
|
const configFileExport = getConfigFileExport(configFileExports, filePathToShowToUser);
|
|
@@ -2,7 +2,7 @@ export { transformFileImports };
|
|
|
2
2
|
export { parseImportData };
|
|
3
3
|
export { isImportData };
|
|
4
4
|
export type { ImportData };
|
|
5
|
-
declare function transformFileImports(code: string, filePathToShowToUser2: string, pointerImports:
|
|
5
|
+
declare function transformFileImports(code: string, filePathToShowToUser2: string, pointerImports: Record<string, boolean> | 'all', skipWarnings?: true): string | null;
|
|
6
6
|
/**
|
|
7
7
|
* Data Structure holding info about import statement:
|
|
8
8
|
* `import { someExport as someImport } from './some-file'`
|
|
@@ -7,7 +7,7 @@ import fs from 'fs';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { import_ } from '@brillout/import';
|
|
10
|
-
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger } from '../../../../utils.js';
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger, assertPathIsFilesystemAbsolute } from '../../../../utils.js';
|
|
11
11
|
import { transformFileImports } from './transformFileImports.js';
|
|
12
12
|
import { vikeConfigDependencies } from '../getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
@@ -79,98 +79,96 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
79
79
|
// Esbuild still sometimes removes unused imports because of TypeScript: https://github.com/evanw/esbuild/issues/3034
|
|
80
80
|
treeShaking: false,
|
|
81
81
|
minify: false,
|
|
82
|
-
metafile:
|
|
83
|
-
bundle:
|
|
82
|
+
metafile: true,
|
|
83
|
+
bundle: true
|
|
84
84
|
};
|
|
85
|
-
let pointerImports;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
setup(build) {
|
|
99
|
-
// https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
85
|
+
let pointerImports = {};
|
|
86
|
+
options.plugins = [
|
|
87
|
+
// Determine whether an import should be:
|
|
88
|
+
// - A pointer import
|
|
89
|
+
// - Externalized
|
|
90
|
+
{
|
|
91
|
+
name: 'vike-esbuild',
|
|
92
|
+
setup(build) {
|
|
93
|
+
// https://github.com/brillout/esbuild-playground
|
|
94
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
95
|
+
if (args.kind !== 'import-statement')
|
|
96
|
+
return;
|
|
97
|
+
// Avoid infinite loop: https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
100
98
|
const useEsbuildResolver = 'useEsbuildResolver';
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// - This is temporary, see comment below.
|
|
122
|
-
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
123
|
-
const isPointerImport =
|
|
99
|
+
if (args.pluginData?.[useEsbuildResolver])
|
|
100
|
+
return;
|
|
101
|
+
const { path, ...opts } = args;
|
|
102
|
+
opts.pluginData = { [useEsbuildResolver]: true };
|
|
103
|
+
const resolved = await build.resolve(path, opts);
|
|
104
|
+
if (resolved.errors.length > 0) {
|
|
105
|
+
/* We could do the following to let Node.js throw the error, but we don't because the error shown by esbuild is prettier: the Node.js error refers to the transpiled [build-f7i251e0iwnw]+config.ts.mjs file which isn't that nice, whereas esbuild refers to the source +config.ts file.
|
|
106
|
+
pointerImports[args.path] = false
|
|
107
|
+
return { external: true }
|
|
108
|
+
*/
|
|
109
|
+
// Let esbuild throw the error. (It throws a nice & pretty error.)
|
|
110
|
+
cleanEsbuildErrors(resolved.errors);
|
|
111
|
+
return resolved;
|
|
112
|
+
}
|
|
113
|
+
assert(resolved.path);
|
|
114
|
+
resolved.path = toPosixPath(resolved.path);
|
|
115
|
+
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
116
|
+
// - This is temporary, see comment below.
|
|
117
|
+
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
118
|
+
const isPointerImport = transformImports === 'all' ||
|
|
124
119
|
// .jsx, .vue, .svg, ... => obviously not config code
|
|
125
120
|
!isJavaScriptFile(resolved.path) ||
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
name: 'vike:dependency-tracker',
|
|
153
|
-
setup(b) {
|
|
154
|
-
b.onLoad({ filter: /./ }, (args) => {
|
|
155
|
-
// We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
|
|
156
|
-
let { path } = args;
|
|
157
|
-
path = toPosixPath(path);
|
|
158
|
-
vikeConfigDependencies.add(path);
|
|
159
|
-
return undefined;
|
|
160
|
-
});
|
|
161
|
-
/* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
|
|
162
|
-
* - Because onLoad() isn't call if the config dependency can't be resolved.
|
|
163
|
-
* - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
|
|
164
|
-
* ```bash
|
|
165
|
-
* mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
|
|
166
|
-
* ```
|
|
167
|
-
* - But implementing a fix is complex and isn't worth it.
|
|
168
|
-
b.onResolve(...)
|
|
169
|
-
*/
|
|
170
|
-
}
|
|
121
|
+
// Import of a Vike extension config => make it a pointer import because we want to show nice error messages (that can display whether a configas been set by the user or by a Vike extension).
|
|
122
|
+
// - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
123
|
+
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
124
|
+
isVikeExtensionConfigImport ||
|
|
125
|
+
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
126
|
+
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
127
|
+
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
128
|
+
resolved.errors.length > 0;
|
|
129
|
+
pointerImports[resolved.path] = isPointerImport;
|
|
130
|
+
assertPosixPath(resolved.path);
|
|
131
|
+
const isExternal = isPointerImport ||
|
|
132
|
+
// Performance: npm package imports that aren't pointer imports can be externalized. For example, if Vike eventually adds support for setting Vite configs in the vike.config.js file, then the user may import a Vite plugin in his vike.config.js file. (We could as well let esbuild always transpile /node_modules/ code but it would be useless and would unnecessarily slow down transpilation.)
|
|
133
|
+
resolved.path.includes('/node_modules/');
|
|
134
|
+
if (debug.isActivated)
|
|
135
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
136
|
+
// We need esbuild to resolve path aliases so that we can use:
|
|
137
|
+
// isNpmPackageImport(str, { cannotBePathAlias: true })
|
|
138
|
+
// assertIsNpmPackageImport()
|
|
139
|
+
assertPathIsFilesystemAbsolute(resolved.path);
|
|
140
|
+
if (isExternal) {
|
|
141
|
+
return { external: true, path: resolved.path };
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
return resolved;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
171
147
|
}
|
|
172
|
-
|
|
173
|
-
|
|
148
|
+
},
|
|
149
|
+
// Track dependencies
|
|
150
|
+
{
|
|
151
|
+
name: 'vike:dependency-tracker',
|
|
152
|
+
setup(b) {
|
|
153
|
+
b.onLoad({ filter: /./ }, (args) => {
|
|
154
|
+
// We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
|
|
155
|
+
let { path } = args;
|
|
156
|
+
path = toPosixPath(path);
|
|
157
|
+
vikeConfigDependencies.add(path);
|
|
158
|
+
return undefined;
|
|
159
|
+
});
|
|
160
|
+
/* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
|
|
161
|
+
* - Because onLoad() isn't call if the config dependency can't be resolved.
|
|
162
|
+
* - For example, the following breaks auto-reload (the config is stuck in its error state and the user needs to touch the importer for the config to reload):
|
|
163
|
+
* ```bash
|
|
164
|
+
* mv ./some-config-dependency.js /tmp/ && mv /tmp/some-config-dependency.js .
|
|
165
|
+
* ```
|
|
166
|
+
* - But implementing a fix is complex and isn't worth it.
|
|
167
|
+
b.onResolve(...)
|
|
168
|
+
*/
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
];
|
|
174
172
|
let result;
|
|
175
173
|
try {
|
|
176
174
|
result = await build(options);
|
|
@@ -180,15 +178,13 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
180
178
|
throw err;
|
|
181
179
|
}
|
|
182
180
|
// Track dependencies
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
});
|
|
191
|
-
}
|
|
181
|
+
assert(result.metafile);
|
|
182
|
+
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
183
|
+
filePathRelative = toPosixPath(filePathRelative);
|
|
184
|
+
assertPosixPath(userRootDir);
|
|
185
|
+
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelative);
|
|
186
|
+
vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
187
|
+
});
|
|
192
188
|
const code = result.outputFiles[0].text;
|
|
193
189
|
assert(typeof code === 'string');
|
|
194
190
|
return { code, pointerImports };
|
|
@@ -310,3 +306,23 @@ function getErrIntroMsg(operation, filePath) {
|
|
|
310
306
|
].join(' ');
|
|
311
307
|
return msg;
|
|
312
308
|
}
|
|
309
|
+
function cleanEsbuildErrors(errors) {
|
|
310
|
+
errors.forEach((e) => (e.notes = e.notes.filter((note) =>
|
|
311
|
+
// Remove note:
|
|
312
|
+
// ```shell
|
|
313
|
+
// You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
|
|
314
|
+
// ```
|
|
315
|
+
//
|
|
316
|
+
// From error:
|
|
317
|
+
// ```shell
|
|
318
|
+
// ✘ [ERROR] Could not resolve "#root/renderer/onRenderHtml_typo" [plugin vike-esbuild]
|
|
319
|
+
//
|
|
320
|
+
// renderer/+config.h.js:1:29:
|
|
321
|
+
// 1 │ import { onRenderHtml } from "#root/renderer/onRenderHtml_typo"
|
|
322
|
+
// ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
323
|
+
//
|
|
324
|
+
// You can mark the path "#root/renderer/onRenderHtml_typo" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.
|
|
325
|
+
//
|
|
326
|
+
// ```
|
|
327
|
+
!note.text.includes('as external to exclude it from the bundle'))));
|
|
328
|
+
}
|
|
@@ -6,10 +6,10 @@ import { assertPosixPath } from './filesystemPathHandling.js';
|
|
|
6
6
|
function assertPathIsFilesystemAbsolute(p) {
|
|
7
7
|
assertPosixPath(p);
|
|
8
8
|
assert(!p.startsWith('/@fs/'));
|
|
9
|
-
if (process.platform
|
|
10
|
-
assert(
|
|
9
|
+
if (process.platform !== 'win32') {
|
|
10
|
+
assert(p.startsWith('/'));
|
|
11
11
|
}
|
|
12
12
|
else {
|
|
13
|
-
assert(
|
|
13
|
+
assert(path.win32.isAbsolute(p));
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.168";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.
|
|
6
|
+
projectVersion: "0.4.168";
|
|
7
7
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.168",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@brillout/json-serializer": "^0.5.8",
|
|
17
17
|
"@brillout/picocolors": "^1.0.10",
|
|
18
18
|
"@brillout/require-shim": "^0.1.2",
|
|
19
|
-
"@brillout/vite-plugin-server-entry": "^0.4.
|
|
19
|
+
"@brillout/vite-plugin-server-entry": "^0.4.5",
|
|
20
20
|
"acorn": "^8.0.0",
|
|
21
21
|
"cac": "^6.0.0",
|
|
22
22
|
"es-module-lexer": "^1.0.0",
|