vike 0.4.167-commit-4996ef0 → 0.4.167-commit-cfadd0a
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/transpileAndExecuteFile.js +97 -92
- package/dist/cjs/utils/assertPathIsFilesystemAbsolute.js +3 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/history.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/history.js +23 -19
- 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 +98 -93
- 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 +1 -1
|
@@ -82,95 +82,98 @@ 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: transformImports !== 'all',
|
|
86
|
+
bundle: transformImports !== 'all'
|
|
87
87
|
};
|
|
88
|
-
let pointerImports
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
88
|
+
let pointerImports;
|
|
89
|
+
if (transformImports === 'all') {
|
|
90
|
+
pointerImports = 'all';
|
|
91
|
+
options.packages = 'external';
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const pointerImports_ = (pointerImports = {});
|
|
95
|
+
options.plugins = [
|
|
96
|
+
// Determine whether an import should be:
|
|
97
|
+
// - A pointer import
|
|
98
|
+
// - Externalized
|
|
99
|
+
{
|
|
100
|
+
name: 'vike-esbuild-plugin',
|
|
101
|
+
setup(build) {
|
|
102
|
+
// https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
103
|
+
const useEsbuildResolver = 'useEsbuildResolver';
|
|
104
|
+
// https://github.com/brillout/esbuild-playground
|
|
105
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
106
|
+
if (args.kind !== 'import-statement')
|
|
107
|
+
return;
|
|
108
|
+
if (args.pluginData?.[useEsbuildResolver])
|
|
109
|
+
return;
|
|
110
|
+
const { path, ...opts } = args;
|
|
111
|
+
opts.pluginData = { [useEsbuildResolver]: true };
|
|
112
|
+
const resolved = await build.resolve(path, opts);
|
|
113
|
+
if (resolved.errors.length > 0) {
|
|
114
|
+
/* 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.
|
|
115
|
+
pointerImports_[args.path] = false
|
|
116
|
+
return { external: true }
|
|
117
|
+
*/
|
|
118
|
+
// Let esbuild throw the error. (It throws a nice & pretty error.)
|
|
119
|
+
return resolved;
|
|
120
|
+
}
|
|
121
|
+
(0, utils_js_1.assert)(resolved.path);
|
|
122
|
+
resolved.path = (0, utils_js_1.toPosixPath)(resolved.path);
|
|
123
|
+
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
124
|
+
// - This is temporary, see comment below.
|
|
125
|
+
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
126
|
+
const isPointerImport =
|
|
121
127
|
// .jsx, .vue, .svg, ... => obviously not config code
|
|
122
128
|
!(0, utils_js_1.isJavaScriptFile)(resolved.path) ||
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
* - But implementing a fix is complex and isn't worth it.
|
|
169
|
-
b.onResolve(...)
|
|
170
|
-
*/
|
|
129
|
+
// 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).
|
|
130
|
+
// - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
131
|
+
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
132
|
+
isVikeExtensionConfigImport ||
|
|
133
|
+
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
134
|
+
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
135
|
+
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
136
|
+
resolved.errors.length > 0;
|
|
137
|
+
pointerImports_[resolved.path] = isPointerImport;
|
|
138
|
+
(0, utils_js_1.assertPosixPath)(resolved.path);
|
|
139
|
+
const isExternal = isPointerImport ||
|
|
140
|
+
// 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.)
|
|
141
|
+
resolved.path.includes('/node_modules/');
|
|
142
|
+
if (debug.isActivated)
|
|
143
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
144
|
+
if (isExternal) {
|
|
145
|
+
return { external: true, path: resolved.path };
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
return resolved;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
// Track dependencies
|
|
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
|
+
}
|
|
171
174
|
}
|
|
172
|
-
|
|
173
|
-
|
|
175
|
+
];
|
|
176
|
+
}
|
|
174
177
|
let result;
|
|
175
178
|
try {
|
|
176
179
|
result = await (0, esbuild_1.build)(options);
|
|
@@ -180,13 +183,15 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
180
183
|
throw err;
|
|
181
184
|
}
|
|
182
185
|
// Track dependencies
|
|
183
|
-
(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
186
|
+
if (transformImports !== 'all') {
|
|
187
|
+
(0, utils_js_1.assert)(result.metafile);
|
|
188
|
+
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
189
|
+
filePathRelative = (0, utils_js_1.toPosixPath)(filePathRelative);
|
|
190
|
+
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
191
|
+
const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathRelative);
|
|
192
|
+
getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
190
195
|
const code = result.outputFiles[0].text;
|
|
191
196
|
(0, utils_js_1.assert)(typeof code === 'string');
|
|
192
197
|
return { code, pointerImports };
|
|
@@ -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)(path_1.default.win32.isAbsolute(p));
|
|
16
16
|
}
|
|
17
17
|
else {
|
|
18
|
-
(0, assert_js_1.assert)(
|
|
18
|
+
(0, assert_js_1.assert)(p.startsWith('/'));
|
|
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.167-commit-
|
|
4
|
+
const PROJECT_VERSION = '0.4.167-commit-cfadd0a';
|
|
5
5
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { initHistoryState, getHistoryState, pushHistory, saveScrollPosition, monkeyPatchHistoryPushState };
|
|
2
|
-
import { assert, assertUsage,
|
|
3
|
-
const globalObject = getGlobalObject('history.ts', {});
|
|
2
|
+
import { assert, assertUsage, hasProp, isObject } from './utils.js';
|
|
4
3
|
// Fill missing state information:
|
|
5
4
|
// - `history.state` can uninitialized (i.e. `null`):
|
|
6
5
|
// - The very first render
|
|
@@ -8,9 +7,10 @@ const globalObject = getGlobalObject('history.ts', {});
|
|
|
8
7
|
// - The user clicks on an anchor link `<a href="#section">Section</a>` (Vike's `onLinkClick()` handler skips hash links).
|
|
9
8
|
// - State information may be incomplete if `history.state` is set by an old Vike version. (E.g. `state.timestamp` was introduced for `pageContext.isBackwardNavigation` in `0.4.19`.)
|
|
10
9
|
function initHistoryState() {
|
|
10
|
+
// No way found to add TypeScript types to `window.history.state`: https://github.com/microsoft/TypeScript/issues/36178
|
|
11
11
|
let state = window.history.state;
|
|
12
12
|
if (!state) {
|
|
13
|
-
state = {};
|
|
13
|
+
state = { _isVikeEnhanced: true };
|
|
14
14
|
}
|
|
15
15
|
let hasModifications = false;
|
|
16
16
|
if (!('timestamp' in state)) {
|
|
@@ -49,7 +49,7 @@ function saveScrollPosition() {
|
|
|
49
49
|
function pushHistory(url, overwriteLastHistoryEntry) {
|
|
50
50
|
if (!overwriteLastHistoryEntry) {
|
|
51
51
|
const timestamp = getTimestamp();
|
|
52
|
-
pushHistoryState({ timestamp, scrollPosition: null, triggeredBy: 'vike' }, url);
|
|
52
|
+
pushHistoryState({ timestamp, scrollPosition: null, triggeredBy: 'vike', _isVikeEnhanced: true }, url);
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
55
|
replaceHistoryState(getHistoryState(), url);
|
|
@@ -69,25 +69,29 @@ function assertState(state) {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
function replaceHistoryState(state, url) {
|
|
72
|
-
|
|
72
|
+
const url_ = url ?? null; // Passing `undefined` chokes older Edge versions.
|
|
73
|
+
window.history.replaceState(state, '', url_);
|
|
73
74
|
}
|
|
74
75
|
function pushHistoryState(state, url) {
|
|
75
|
-
pushStateOriginal(
|
|
76
|
+
// Vike should call window.history.pushState() (and not the orignal `pushStateOriginal()`) so that other tools (e.g. user tracking) can listen to Vike's pushState() calls, see https://github.com/vikejs/vike/issues/1582.
|
|
77
|
+
window.history.pushState(state, '', url);
|
|
76
78
|
}
|
|
77
79
|
function monkeyPatchHistoryPushState() {
|
|
78
|
-
|
|
79
|
-
window.history.pushState = (
|
|
80
|
-
assertUsage(
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
const pushStateOriginal = window.history.pushState.bind(window.history);
|
|
81
|
+
window.history.pushState = (stateOriginal = {}, ...rest) => {
|
|
82
|
+
assertUsage(stateOriginal === undefined || stateOriginal === null || isObject(stateOriginal), 'history.pushState(state) argument state must be an object');
|
|
83
|
+
const stateEnhanced = isVikeEnhanced(stateOriginal)
|
|
84
|
+
? stateOriginal
|
|
85
|
+
: {
|
|
86
|
+
_isVikeEnhanced: true,
|
|
87
|
+
scrollPosition: getScrollPosition(),
|
|
88
|
+
timestamp: getTimestamp(),
|
|
89
|
+
triggeredBy: 'user',
|
|
90
|
+
...stateOriginal
|
|
91
|
+
};
|
|
92
|
+
return pushStateOriginal(stateEnhanced, ...rest);
|
|
89
93
|
};
|
|
90
94
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
95
|
+
function isVikeEnhanced(state) {
|
|
96
|
+
return isObject(state) && '_isVikeEnhanced' in state;
|
|
93
97
|
}
|
|
@@ -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: Record<string, boolean
|
|
5
|
+
declare function transformFileImports(code: string, filePathToShowToUser2: string, pointerImports: 'all' | Record<string, boolean>, 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
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isJavaScriptFile, createDebugger } 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,95 +79,98 @@ 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: transformImports !== 'all',
|
|
83
|
+
bundle: transformImports !== 'all'
|
|
84
84
|
};
|
|
85
|
-
let pointerImports
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
85
|
+
let pointerImports;
|
|
86
|
+
if (transformImports === 'all') {
|
|
87
|
+
pointerImports = 'all';
|
|
88
|
+
options.packages = 'external';
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const pointerImports_ = (pointerImports = {});
|
|
92
|
+
options.plugins = [
|
|
93
|
+
// Determine whether an import should be:
|
|
94
|
+
// - A pointer import
|
|
95
|
+
// - Externalized
|
|
96
|
+
{
|
|
97
|
+
name: 'vike-esbuild-plugin',
|
|
98
|
+
setup(build) {
|
|
99
|
+
// https://github.com/evanw/esbuild/issues/3095#issuecomment-1546916366
|
|
100
|
+
const useEsbuildResolver = 'useEsbuildResolver';
|
|
101
|
+
// https://github.com/brillout/esbuild-playground
|
|
102
|
+
build.onResolve({ filter: /.*/ }, async (args) => {
|
|
103
|
+
if (args.kind !== 'import-statement')
|
|
104
|
+
return;
|
|
105
|
+
if (args.pluginData?.[useEsbuildResolver])
|
|
106
|
+
return;
|
|
107
|
+
const { path, ...opts } = args;
|
|
108
|
+
opts.pluginData = { [useEsbuildResolver]: true };
|
|
109
|
+
const resolved = await build.resolve(path, opts);
|
|
110
|
+
if (resolved.errors.length > 0) {
|
|
111
|
+
/* 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.
|
|
112
|
+
pointerImports_[args.path] = false
|
|
113
|
+
return { external: true }
|
|
114
|
+
*/
|
|
115
|
+
// Let esbuild throw the error. (It throws a nice & pretty error.)
|
|
116
|
+
return resolved;
|
|
117
|
+
}
|
|
118
|
+
assert(resolved.path);
|
|
119
|
+
resolved.path = toPosixPath(resolved.path);
|
|
120
|
+
// vike-{react,vue,solid} follow the convention that their config export resolves to a file named +config.js
|
|
121
|
+
// - This is temporary, see comment below.
|
|
122
|
+
const isVikeExtensionConfigImport = resolved.path.endsWith('+config.js');
|
|
123
|
+
const isPointerImport =
|
|
118
124
|
// .jsx, .vue, .svg, ... => obviously not config code
|
|
119
125
|
!isJavaScriptFile(resolved.path) ||
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
* - But implementing a fix is complex and isn't worth it.
|
|
166
|
-
b.onResolve(...)
|
|
167
|
-
*/
|
|
126
|
+
// 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).
|
|
127
|
+
// - We should have Node.js directly load vike-{react,vue,solid} while enforcing Vike extensions to set 'name' in their +config.js file.
|
|
128
|
+
// - vike@0.4.162 already started soft-requiring Vike extensions to set the name config
|
|
129
|
+
isVikeExtensionConfigImport ||
|
|
130
|
+
// Cannot be resolved by esbuild => take a leap of faith and make it a pointer import.
|
|
131
|
+
// - For example if esbuild cannot resolve a path alias while Vite can.
|
|
132
|
+
// - When tsconfig.js#compilerOptions.paths is set, then esbuild is able to resolve the path alias.
|
|
133
|
+
resolved.errors.length > 0;
|
|
134
|
+
pointerImports_[resolved.path] = isPointerImport;
|
|
135
|
+
assertPosixPath(resolved.path);
|
|
136
|
+
const isExternal = isPointerImport ||
|
|
137
|
+
// 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.)
|
|
138
|
+
resolved.path.includes('/node_modules/');
|
|
139
|
+
if (debug.isActivated)
|
|
140
|
+
debug('onResolved()', { args, resolved, isPointerImport, isExternal });
|
|
141
|
+
if (isExternal) {
|
|
142
|
+
return { external: true, path: resolved.path };
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return resolved;
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
// Track dependencies
|
|
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
|
+
}
|
|
168
171
|
}
|
|
169
|
-
|
|
170
|
-
|
|
172
|
+
];
|
|
173
|
+
}
|
|
171
174
|
let result;
|
|
172
175
|
try {
|
|
173
176
|
result = await build(options);
|
|
@@ -177,13 +180,15 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
|
|
|
177
180
|
throw err;
|
|
178
181
|
}
|
|
179
182
|
// Track dependencies
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
filePathRelative
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
if (transformImports !== 'all') {
|
|
184
|
+
assert(result.metafile);
|
|
185
|
+
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
186
|
+
filePathRelative = toPosixPath(filePathRelative);
|
|
187
|
+
assertPosixPath(userRootDir);
|
|
188
|
+
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelative);
|
|
189
|
+
vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
187
192
|
const code = result.outputFiles[0].text;
|
|
188
193
|
assert(typeof code === 'string');
|
|
189
194
|
return { code, pointerImports };
|
|
@@ -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(path.win32.isAbsolute(p));
|
|
11
11
|
}
|
|
12
12
|
else {
|
|
13
|
-
assert(
|
|
13
|
+
assert(p.startsWith('/'));
|
|
14
14
|
}
|
|
15
15
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.167-commit-
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.167-commit-cfadd0a";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.167-commit-
|
|
6
|
+
projectVersion: "0.4.167-commit-cfadd0a";
|
|
7
7
|
};
|