vike 0.4.150 → 0.4.151
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/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/assertFileEnv.js +107 -0
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +3 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +17 -36
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/resolveExtensions.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -1
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +38 -0
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +57 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +7 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +46 -28
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwc.js +5 -5
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwcBig.js +4 -4
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueCss.js +7 -7
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueHtml.js +2 -2
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueJavascript.js +3 -3
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +2 -1
- package/dist/cjs/node/runtime/index-deprecated.js +3 -2
- package/dist/cjs/node/runtime/index.js +3 -2
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +33 -0
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -4
- package/dist/cjs/shared/route/resolveRedirects.js +2 -10
- package/dist/cjs/shared/route/resolveUrlPathname.js +48 -0
- package/dist/cjs/utils/debug.js +29 -15
- package/dist/cjs/utils/getDependencyPackageJson.js +1 -1
- package/dist/cjs/utils/getFilePathAbsolute.js +1 -1
- package/dist/cjs/utils/getOutDirs.js +11 -1
- package/dist/cjs/utils/injectRollupInputs.js +29 -0
- package/dist/cjs/utils/isPlainObject.js +1 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/requireResolve.js +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +105 -66
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +1 -1
- package/dist/esm/node/plugin/index.js +3 -3
- package/dist/esm/node/plugin/plugins/assertFileEnv.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/assertFileEnv.js +101 -0
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +3 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +17 -36
- package/dist/esm/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/config/resolveExtensions.js +1 -1
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -1
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +32 -0
- package/dist/esm/node/plugin/plugins/importBuild/index.js +59 -21
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/debug.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +7 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +47 -29
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwc.js +5 -5
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwcBig.js +4 -4
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueCss.js +7 -7
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueHtml.js +2 -2
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueJavascript.js +3 -3
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +2 -1
- package/dist/esm/node/runtime/index-deprecated.js +3 -2
- package/dist/esm/node/runtime/index.js +3 -2
- package/dist/esm/node/runtime/renderPage/{executeOnBeforeRenderHook.d.ts → executeOnBeforeRenderAndDataHooks.d.ts} +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +30 -0
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -4
- package/dist/esm/shared/VikeNamespace.d.ts +2 -1
- package/dist/esm/shared/page-configs/Config.d.ts +22 -5
- package/dist/esm/shared/route/resolveRedirects.js +2 -10
- package/dist/esm/shared/route/resolveUrlPathname.d.ts +12 -0
- package/dist/esm/shared/route/resolveUrlPathname.js +45 -0
- package/dist/esm/shared/types.d.ts +5 -0
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/debug.d.ts +2 -2
- package/dist/esm/utils/debug.js +29 -15
- package/dist/esm/utils/debugGlob.d.ts +1 -1
- package/dist/esm/utils/getDependencyPackageJson.js +1 -1
- package/dist/esm/utils/getFilePathAbsolute.js +1 -1
- package/dist/esm/utils/getOutDirs.js +11 -1
- package/dist/esm/utils/injectRollupInputs.d.ts +7 -0
- package/dist/esm/utils/injectRollupInputs.js +26 -0
- package/dist/esm/utils/isPlainObject.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/requireResolve.js +1 -1
- package/package.json +9 -2
- package/dist/cjs/node/plugin/plugins/manifest.js +0 -59
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderHook.js +0 -23
- package/dist/esm/node/plugin/plugins/manifest.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/manifest.js +0 -53
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderHook.js +0 -20
|
@@ -12,7 +12,6 @@ const buildConfig_js_1 = require("./plugins/buildConfig.js");
|
|
|
12
12
|
const previewConfig_js_1 = require("./plugins/previewConfig.js");
|
|
13
13
|
const autoFullBuild_js_1 = require("./plugins/autoFullBuild.js");
|
|
14
14
|
const index_js_1 = require("./plugins/devConfig/index.js");
|
|
15
|
-
const manifest_js_1 = require("./plugins/manifest.js");
|
|
16
15
|
const packageJsonFile_js_1 = require("./plugins/packageJsonFile.js");
|
|
17
16
|
const removeRequireHookPlugin_js_1 = require("./plugins/removeRequireHookPlugin.js");
|
|
18
17
|
const index_js_2 = require("./plugins/importUserCode/index.js");
|
|
@@ -28,6 +27,7 @@ const extensionsAssets_js_1 = require("./plugins/extensionsAssets.js");
|
|
|
28
27
|
const baseUrls_js_1 = require("./plugins/baseUrls.js");
|
|
29
28
|
const envVars_js_1 = require("./plugins/envVars.js");
|
|
30
29
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
30
|
+
const assertFileEnv_js_1 = require("./plugins/assertFileEnv.js");
|
|
31
31
|
(0, utils_js_2.markEnvAsVite)();
|
|
32
32
|
// Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
|
|
33
33
|
function plugin(vikeConfig) {
|
|
@@ -39,7 +39,6 @@ function plugin(vikeConfig) {
|
|
|
39
39
|
(0, buildConfig_js_1.buildConfig)(),
|
|
40
40
|
(0, previewConfig_js_1.previewConfig)(),
|
|
41
41
|
...(0, autoFullBuild_js_1.autoFullBuild)(),
|
|
42
|
-
...(0, manifest_js_1.manifest)(),
|
|
43
42
|
(0, packageJsonFile_js_1.packageJsonFile)(),
|
|
44
43
|
(0, removeRequireHookPlugin_js_1.removeRequireHookPlugin)(),
|
|
45
44
|
(0, distFileNames_js_1.distFileNames)(),
|
|
@@ -50,7 +49,8 @@ function plugin(vikeConfig) {
|
|
|
50
49
|
...(0, index_js_4.importBuild)(),
|
|
51
50
|
(0, extensionsAssets_js_1.extensionsAssets)(),
|
|
52
51
|
(0, baseUrls_js_1.baseUrls)(vikeConfig),
|
|
53
|
-
(0, envVars_js_1.envVarsPlugin)()
|
|
52
|
+
(0, envVars_js_1.envVarsPlugin)(),
|
|
53
|
+
(0, assertFileEnv_js_1.assertFileEnv)()
|
|
54
54
|
];
|
|
55
55
|
return plugins;
|
|
56
56
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.assertFileEnv = void 0;
|
|
7
|
+
const utils_js_1 = require("../utils.js");
|
|
8
|
+
const extractAssetsPlugin_js_1 = require("./extractAssetsPlugin.js");
|
|
9
|
+
const extractExportNamesPlugin_js_1 = require("./extractExportNamesPlugin.js");
|
|
10
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
|
+
function assertFileEnv() {
|
|
12
|
+
let config;
|
|
13
|
+
let isDev = false;
|
|
14
|
+
return {
|
|
15
|
+
name: 'vike:assertFileEnv',
|
|
16
|
+
// - We need to set `enforce: 'pre'` because, otherwise, the resolvedId() hook of Vite's internal plugin `vite:resolve` is called before and it doesn't seem to call `this.resolve()` which means that the resolveId() hook below is never called.
|
|
17
|
+
// - Vite's `vite:resolve` plugin: https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/resolve.ts#L105
|
|
18
|
+
// - It's actually a good thing if the resolveId() hook below is the first one to be called because it doesn't actually resolve any ID, so all other resolveId() hooks will be called as normal. And with `this.resolve()` we get the information we want from all other resolvedId() hooks.
|
|
19
|
+
// - Path aliases are already resolved, even when using `enforce: 'pre'`. For example:
|
|
20
|
+
// ```js
|
|
21
|
+
// // /pages/index/+Page.tsx
|
|
22
|
+
//
|
|
23
|
+
// // The value of `source` is `/home/rom/code/vike/examples/path-aliases/components/Counter` (instead of `#root/components/Counter`)
|
|
24
|
+
// // The value of `importer` is `/home/rom/code/vike/examples/path-aliases/pages/index/+Page.tsx`
|
|
25
|
+
// import { Counter } from '#root/components/Counter'
|
|
26
|
+
// ```
|
|
27
|
+
enforce: 'pre',
|
|
28
|
+
resolveId: {
|
|
29
|
+
/* I don't know why, but path aliases aren't resolved anymore when setting `order: 'pre'`. (In principle, I'd assume that `this.resolve()` would resolve the alias but it doesn't.)
|
|
30
|
+
order: 'pre',
|
|
31
|
+
*/
|
|
32
|
+
async handler(source, importer, options) {
|
|
33
|
+
// TODO/v1-release: remove
|
|
34
|
+
if (extractAssetsPlugin_js_1.extractAssetsRE.test(source) || extractExportNamesPlugin_js_1.extractExportNamesRE.test(source))
|
|
35
|
+
return;
|
|
36
|
+
// Seems like Vite is doing some funky stuff here.
|
|
37
|
+
if (importer?.endsWith('.html'))
|
|
38
|
+
return;
|
|
39
|
+
const resolved = await this.resolve(source, importer, {
|
|
40
|
+
// Needed for old Vite plugins: https://vitejs.dev/guide/migration#rollup-4:~:text=For%20Vite%20plugins%2C%20this.resolve%20skipSelf%20option%20is%20now%20true%20by%20default.
|
|
41
|
+
skipSelf: true,
|
|
42
|
+
...options
|
|
43
|
+
});
|
|
44
|
+
// resolved is null when import path is erroneous and doesn't actually point to a file
|
|
45
|
+
if (!resolved)
|
|
46
|
+
return;
|
|
47
|
+
const modulePath = resolved.id.split('?')[0];
|
|
48
|
+
// `.server.js` and `.client.js` should only apply to user files
|
|
49
|
+
if (modulePath.includes('/node_modules/'))
|
|
50
|
+
return;
|
|
51
|
+
// TODO/v1-release: remove
|
|
52
|
+
if (modulePath.endsWith('.css'))
|
|
53
|
+
return;
|
|
54
|
+
const isServerSide = options?.ssr;
|
|
55
|
+
const envActual = isServerSide ? 'server' : 'client';
|
|
56
|
+
const envExpect = isServerSide ? 'client' : 'server';
|
|
57
|
+
const suffix = `.${envExpect}.`;
|
|
58
|
+
// Everything nonimal
|
|
59
|
+
if (!modulePath.includes(suffix))
|
|
60
|
+
return;
|
|
61
|
+
// Show error message
|
|
62
|
+
let errMsg;
|
|
63
|
+
let modulePathPretty = (0, utils_js_1.getFilePathRelativeToUserRootDir)(modulePath, config.root);
|
|
64
|
+
modulePathPretty = modulePathPretty.replaceAll(suffix, picocolors_1.default.bold(suffix));
|
|
65
|
+
errMsg = `${(0, utils_js_1.capitalizeFirstLetter)(envExpect)}-only module ${modulePathPretty} (https://vike.dev/file-env) imported on the ${envActual}-side`;
|
|
66
|
+
if (importer &&
|
|
67
|
+
// Don't show Vike's virtual modules that import the entry plus files such as /pages/about/+Page.js
|
|
68
|
+
!importer.includes('virtual:vike:') &&
|
|
69
|
+
// I don't know why and who sets importer to '<stdin>' (I guess Vite?)
|
|
70
|
+
importer !== '<stdin>') {
|
|
71
|
+
const importerPath = (0, utils_js_1.getFilePathRelativeToUserRootDir)(importer.split('?')[0], config.root);
|
|
72
|
+
errMsg += ` by ${importerPath}`;
|
|
73
|
+
}
|
|
74
|
+
if (isDev) {
|
|
75
|
+
errMsg += ' (building your app for production will be prevented and an error will be thrown)';
|
|
76
|
+
}
|
|
77
|
+
errMsg += '.';
|
|
78
|
+
if (isDev) {
|
|
79
|
+
(0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: true });
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
configResolved(config_) {
|
|
87
|
+
config = config_;
|
|
88
|
+
},
|
|
89
|
+
configureServer() {
|
|
90
|
+
isDev = true;
|
|
91
|
+
},
|
|
92
|
+
// Ensure this plugin works
|
|
93
|
+
transform(_code, id, options) {
|
|
94
|
+
if (isDev)
|
|
95
|
+
return;
|
|
96
|
+
// TODO/v1-release: remove
|
|
97
|
+
if (extractAssetsPlugin_js_1.extractAssetsRE.test(id) || extractExportNamesPlugin_js_1.extractExportNamesRE.test(id))
|
|
98
|
+
return;
|
|
99
|
+
if (id.split('?')[0].endsWith('.css'))
|
|
100
|
+
return;
|
|
101
|
+
const isServerSide = options?.ssr;
|
|
102
|
+
const envWrong = isServerSide ? 'client' : 'server';
|
|
103
|
+
(0, utils_js_1.assert)(!id.includes(`.${envWrong}.`));
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
exports.assertFileEnv = assertFileEnv;
|
|
@@ -63,9 +63,10 @@ async function triggerFullBuild(config, configVike, bundle) {
|
|
|
63
63
|
return; // already triggered
|
|
64
64
|
if (isDisabled(configVike))
|
|
65
65
|
return;
|
|
66
|
+
/* Is this @vitejs/plugin-legacy workaround still needed? Should we re-implement it?
|
|
66
67
|
// vike.json missing => it isn't a `$ vite build` call (e.g. @vitejs/plugin-legacy calls Vite's build() API) => skip
|
|
67
|
-
if (!bundle['vike.json'])
|
|
68
|
-
|
|
68
|
+
if (!bundle['vike.json']) return
|
|
69
|
+
*/
|
|
69
70
|
const configFromCli = !(0, isViteCliCall_js_1.isViteCliCall)() ? null : (0, isViteCliCall_js_1.getViteConfigFromCli)();
|
|
70
71
|
const configInline = {
|
|
71
72
|
...configFromCli,
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.analyzeClientEntries = exports.assertRollupInput = exports.buildConfig = void 0;
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
|
-
const virtualFileImportUserCode_js_1 = require("../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
9
8
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
10
9
|
const helpers_js_1 = require("../../../shared/page-configs/helpers.js");
|
|
11
10
|
const findPageFiles_js_1 = require("../shared/findPageFiles.js");
|
|
@@ -16,7 +15,7 @@ const module_1 = require("module");
|
|
|
16
15
|
const getClientEntryFilePath_js_1 = require("../../shared/getClientEntryFilePath.js");
|
|
17
16
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
18
17
|
const path_1 = __importDefault(require("path"));
|
|
19
|
-
// @ts-ignore
|
|
18
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
20
19
|
const importMetaUrl = `file://${__filename}`;
|
|
21
20
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
22
21
|
const manifestTempFile = '_temp_manifest.json';
|
|
@@ -30,14 +29,9 @@ function buildConfig() {
|
|
|
30
29
|
order: 'post',
|
|
31
30
|
async handler(config) {
|
|
32
31
|
assertRollupInput(config);
|
|
33
|
-
const userInputs = normalizeRollupInput(config.build.rollupOptions.input);
|
|
34
32
|
const entries = await getEntries(config);
|
|
35
33
|
(0, utils_js_1.assert)(Object.keys(entries).length > 0);
|
|
36
|
-
|
|
37
|
-
...entries,
|
|
38
|
-
...userInputs
|
|
39
|
-
};
|
|
40
|
-
config.build.rollupOptions.input = input;
|
|
34
|
+
config.build.rollupOptions.input = (0, utils_js_1.injectRollupInputs)(entries, config);
|
|
41
35
|
addLogHook();
|
|
42
36
|
}
|
|
43
37
|
},
|
|
@@ -76,12 +70,12 @@ async function getEntries(config) {
|
|
|
76
70
|
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config, false);
|
|
77
71
|
(0, utils_js_1.assertUsage)(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
78
72
|
if ((0, utils_js_1.viteIsSSR)(config)) {
|
|
79
|
-
const
|
|
73
|
+
const pageEntries = getPageEntries(pageConfigs);
|
|
80
74
|
const entries = {
|
|
81
|
-
|
|
82
|
-
importBuild: resolve('dist/esm/node/importBuild.js'),
|
|
75
|
+
// importBuild: resolve('dist/esm/node/importBuild.js'), // TODO/next-major-release: remove
|
|
83
76
|
...pageFileEntries,
|
|
84
|
-
|
|
77
|
+
// Ensure Rollup generates a bundle per page: https://github.com/vikejs/vike/issues/349#issuecomment-1166247275
|
|
78
|
+
...pageEntries
|
|
85
79
|
};
|
|
86
80
|
return entries;
|
|
87
81
|
}
|
|
@@ -106,6 +100,14 @@ async function getEntries(config) {
|
|
|
106
100
|
return entries;
|
|
107
101
|
}
|
|
108
102
|
}
|
|
103
|
+
function getPageEntries(pageConfigs) {
|
|
104
|
+
const pageEntries = {};
|
|
105
|
+
pageConfigs.forEach((pageConfig) => {
|
|
106
|
+
const { entryName, entryTarget } = getEntryFromPageConfig(pageConfig, false);
|
|
107
|
+
pageEntries[entryName] = entryTarget;
|
|
108
|
+
});
|
|
109
|
+
return pageEntries;
|
|
110
|
+
}
|
|
109
111
|
function analyzeClientEntries(pageConfigs, config) {
|
|
110
112
|
let hasClientRouting = false;
|
|
111
113
|
let hasServerRouting = false;
|
|
@@ -120,6 +122,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
120
122
|
hasServerRouting = true;
|
|
121
123
|
}
|
|
122
124
|
{
|
|
125
|
+
// Ensure Rollup generates a bundle per page: https://github.com/vikejs/vike/issues/349#issuecomment-1166247275
|
|
123
126
|
const { entryName, entryTarget } = getEntryFromPageConfig(pageConfig, true);
|
|
124
127
|
clientEntries[entryName] = entryTarget;
|
|
125
128
|
}
|
|
@@ -138,14 +141,6 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
138
141
|
return { hasClientRouting, hasServerRouting, clientEntries };
|
|
139
142
|
}
|
|
140
143
|
exports.analyzeClientEntries = analyzeClientEntries;
|
|
141
|
-
function analyzeServerEntries(pageConfigs) {
|
|
142
|
-
const serverEntries = {};
|
|
143
|
-
pageConfigs.forEach((pageConfig) => {
|
|
144
|
-
const { entryName, entryTarget } = getEntryFromPageConfig(pageConfig, false);
|
|
145
|
-
serverEntries[entryName] = entryTarget;
|
|
146
|
-
});
|
|
147
|
-
return serverEntries;
|
|
148
|
-
}
|
|
149
144
|
// Ensure Rollup creates entries for each page file, see https://github.com/vikejs/vike/issues/350
|
|
150
145
|
// (Otherwise the page files may be missing in the client manifest.json)
|
|
151
146
|
async function getPageFileEntries(config, includeAssetsImportedByServer) {
|
|
@@ -201,20 +196,6 @@ function resolve(filePath) {
|
|
|
201
196
|
// [RELATIVE_PATH_FROM_DIST] Current directory: node_modules/vike/dist/esm/node/plugin/plugins/
|
|
202
197
|
return require_.resolve(`../../../../../${filePath}`);
|
|
203
198
|
}
|
|
204
|
-
function normalizeRollupInput(input) {
|
|
205
|
-
if (!input) {
|
|
206
|
-
return {};
|
|
207
|
-
}
|
|
208
|
-
// Usually `input` is an oject, but the user can set it as a `string` or `string[]`
|
|
209
|
-
if (typeof input === 'string') {
|
|
210
|
-
input = [input];
|
|
211
|
-
}
|
|
212
|
-
if (Array.isArray(input)) {
|
|
213
|
-
return Object.fromEntries(input.map((input) => [input, input]));
|
|
214
|
-
}
|
|
215
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(input));
|
|
216
|
-
return input;
|
|
217
|
-
}
|
|
218
199
|
function addLogHook() {
|
|
219
200
|
const tty = process.stdout.isTTY && !process.env.CI; // Equals https://github.com/vitejs/vite/blob/193d55c7b9cbfec5b79ebfca276d4a721e7de14d/packages/vite/src/node/plugins/reporter.ts#L27
|
|
220
201
|
if (!tty)
|
|
@@ -243,9 +224,9 @@ function addLogHook() {
|
|
|
243
224
|
});
|
|
244
225
|
}
|
|
245
226
|
function assertRollupInput(config) {
|
|
246
|
-
const userInputs = normalizeRollupInput(config.build.rollupOptions.input);
|
|
227
|
+
const userInputs = (0, utils_js_1.normalizeRollupInput)(config.build.rollupOptions.input);
|
|
247
228
|
const htmlInputs = Object.values(userInputs).filter((entry) => entry.endsWith('.html') || entry.endsWith('.htm'));
|
|
248
229
|
const htmlInput = htmlInputs[0];
|
|
249
|
-
(0, utils_js_1.assertUsage)(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using
|
|
230
|
+
(0, utils_js_1.assertUsage)(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using Vike, instead follow https://vike.dev/add`);
|
|
250
231
|
}
|
|
251
232
|
exports.assertRollupInput = assertRollupInput;
|
|
@@ -11,7 +11,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
12
|
const module_1 = require("module");
|
|
13
13
|
const assertResolveAlias_js_1 = require("./commonConfig/assertResolveAlias.js");
|
|
14
|
-
// @ts-ignore
|
|
14
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
15
15
|
const importMetaUrl = `file://${__filename}`;
|
|
16
16
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
17
17
|
function commonConfig() {
|
|
@@ -10,7 +10,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
10
10
|
const fileTypes_js_1 = require("../../../../shared/getPageFiles/fileTypes.js");
|
|
11
11
|
const module_1 = require("module");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
// @ts-ignore
|
|
13
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
14
14
|
const importMetaUrl = `file://${__filename}`;
|
|
15
15
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
16
16
|
function resolveExtensions(configs, config) {
|
|
@@ -9,7 +9,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
9
9
|
const utils_js_1 = require("../../utils.js");
|
|
10
10
|
const import_1 = require("@brillout/import");
|
|
11
11
|
const module_1 = require("module");
|
|
12
|
-
// @ts-ignore
|
|
12
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
13
13
|
const importMetaUrl = `file://${__filename}`;
|
|
14
14
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
15
15
|
async function getStemPackages(userAppRootDir) {
|
|
@@ -11,7 +11,7 @@ const utils_js_1 = require("../../utils.js");
|
|
|
11
11
|
const module_1 = require("module");
|
|
12
12
|
const path_2 = require("path");
|
|
13
13
|
const url_1 = require("url");
|
|
14
|
-
// @ts-ignore
|
|
14
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
15
15
|
const importMetaUrl = `file://${__filename}`;
|
|
16
16
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
17
17
|
const __dirname_ = (0, path_2.dirname)((0, url_1.fileURLToPath)(importMetaUrl));
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getVikeManifest = void 0;
|
|
7
|
+
const utils_js_1 = require("../../utils.js");
|
|
8
|
+
const assertPluginManifest_js_1 = require("../../../shared/assertPluginManifest.js");
|
|
9
|
+
const extractExportNamesPlugin_js_1 = require("../extractExportNamesPlugin.js");
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const globalContext_js_1 = require("../../../runtime/globalContext.js");
|
|
12
|
+
function getVikeManifest(config, configVike) {
|
|
13
|
+
const runtimeManifest = (0, globalContext_js_1.getRuntimeManifest)(configVike);
|
|
14
|
+
const manifest = {
|
|
15
|
+
version: utils_js_1.projectInfo.projectVersion,
|
|
16
|
+
usesClientRouter: (0, extractExportNamesPlugin_js_1.isUsingClientRouter)(),
|
|
17
|
+
manifestKeyMap: getManifestKeyMap(configVike, config),
|
|
18
|
+
...runtimeManifest
|
|
19
|
+
};
|
|
20
|
+
(0, assertPluginManifest_js_1.assertPluginManifest)(manifest);
|
|
21
|
+
return manifest;
|
|
22
|
+
}
|
|
23
|
+
exports.getVikeManifest = getVikeManifest;
|
|
24
|
+
function getManifestKeyMap(configVike, config) {
|
|
25
|
+
const manifestKeyMap = {};
|
|
26
|
+
configVike.extensions
|
|
27
|
+
.map(({ pageConfigsDistFiles }) => pageConfigsDistFiles)
|
|
28
|
+
.flat()
|
|
29
|
+
.filter(utils_js_1.isNotNullish)
|
|
30
|
+
.forEach(({ importPath, filePath }) => {
|
|
31
|
+
// Recreating https://github.com/vitejs/vite/blob/8158ece72b66307e7b607b98496891610ca70ea2/packages/vite/src/node/plugins/manifest.ts#L38
|
|
32
|
+
const filePathRelative = path_1.default.posix.relative(config.root, (0, utils_js_1.toPosixPath)(filePath));
|
|
33
|
+
(0, utils_js_1.assertPosixPath)(filePathRelative);
|
|
34
|
+
(0, utils_js_1.assertPosixPath)(importPath);
|
|
35
|
+
manifestKeyMap[importPath] = filePathRelative;
|
|
36
|
+
});
|
|
37
|
+
return manifestKeyMap;
|
|
38
|
+
}
|
|
@@ -8,47 +8,85 @@ const plugin_js_1 = require("@brillout/vite-plugin-import-build/plugin.js");
|
|
|
8
8
|
const utils_js_1 = require("../../utils.js");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const module_1 = require("module");
|
|
11
|
-
|
|
11
|
+
const getConfigVike_js_1 = require("../../../shared/getConfigVike.js");
|
|
12
|
+
const getVikeManifest_js_1 = require("./getVikeManifest.js");
|
|
13
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
14
|
+
const virtualFileImportUserCode_js_1 = require("../../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
15
|
+
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
12
16
|
const importMetaUrl = `file://${__filename}`;
|
|
13
17
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
18
|
+
const ASSETS_MAP = '__VITE_ASSETS_MAP__';
|
|
14
19
|
function importBuild() {
|
|
15
20
|
let config;
|
|
21
|
+
let configVike;
|
|
16
22
|
return [
|
|
17
23
|
{
|
|
18
24
|
name: 'vike:importBuild:config',
|
|
19
25
|
enforce: 'post',
|
|
20
|
-
configResolved(config_) {
|
|
26
|
+
async configResolved(config_) {
|
|
21
27
|
config = config_;
|
|
28
|
+
configVike = await (0, getConfigVike_js_1.getConfigVike)(config);
|
|
29
|
+
},
|
|
30
|
+
async writeBundle(options, bundle) {
|
|
31
|
+
if (!(0, utils_js_1.viteIsSSR)(config))
|
|
32
|
+
return;
|
|
33
|
+
await replace_ASSETS_MAP(options, bundle);
|
|
22
34
|
}
|
|
23
35
|
},
|
|
24
36
|
(0, plugin_js_1.importBuild)({
|
|
25
|
-
getImporterCode: (
|
|
26
|
-
|
|
27
|
-
return getImporterCode(config, pageFilesEntry);
|
|
37
|
+
getImporterCode: () => {
|
|
38
|
+
return getEntryCode(config, configVike);
|
|
28
39
|
},
|
|
29
40
|
libraryName: utils_js_1.projectInfo.projectName
|
|
30
41
|
})
|
|
31
42
|
];
|
|
32
43
|
}
|
|
33
44
|
exports.importBuild = importBuild;
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
require_.resolve(`../../../../../../dist/esm/node/runtime/globalContext/loadImportBuild.js`));
|
|
38
|
-
const { outDirServer } = (0, utils_js_1.getOutDirs)(config);
|
|
39
|
-
const filePathRelative = path_1.default.posix.relative(outDirServer, filePathAbsolute);
|
|
40
|
-
// The only reason we went for using CJS require() instead of ESM import() is because import() doesn't support .json files
|
|
45
|
+
function getEntryCode(config, configVike) {
|
|
46
|
+
const importPath = getImportPath(config);
|
|
47
|
+
const vikeManifest = (0, getVikeManifest_js_1.getVikeManifest)(config, configVike);
|
|
41
48
|
const importerCode = [
|
|
42
|
-
|
|
43
|
-
`
|
|
49
|
+
` import { setImportBuildGetters } from '${importPath}';`,
|
|
50
|
+
` import * as pageFiles from '${virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer}';`,
|
|
44
51
|
' setImportBuildGetters({',
|
|
45
|
-
` pageFiles: () =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
` pageFiles: () => pageFiles,`,
|
|
53
|
+
// TODO: rename clientManifest -> assetManifest
|
|
54
|
+
` clientManifest: () => { return ${ASSETS_MAP} },`,
|
|
55
|
+
// TODO: rename pluginManifest -> vikeManifest
|
|
56
|
+
` pluginManifest: () => (${JSON.stringify(vikeManifest, null, 2)}),`,
|
|
49
57
|
' });',
|
|
50
|
-
'})()',
|
|
51
58
|
''
|
|
52
59
|
].join('\n');
|
|
53
60
|
return importerCode;
|
|
54
61
|
}
|
|
62
|
+
async function replace_ASSETS_MAP(options, bundle) {
|
|
63
|
+
const { dir } = options;
|
|
64
|
+
(0, utils_js_1.assert)(dir);
|
|
65
|
+
// I guess importBuild won't be found in the bundle when using @vitejs/plugin-legacy
|
|
66
|
+
const importBuildEntry = (0, plugin_js_1.findImportBuildBundleEntry)(bundle);
|
|
67
|
+
const importBuildFilePath = path_1.default.join(dir, importBuildEntry.fileName);
|
|
68
|
+
const assetsJsonFilePath = path_1.default.join(dir, '..', 'assets.json');
|
|
69
|
+
const [assetsJsonString, importBuildFileContent] = await Promise.all([
|
|
70
|
+
await promises_1.default.readFile(assetsJsonFilePath, 'utf8'),
|
|
71
|
+
await promises_1.default.readFile(importBuildFilePath, 'utf8')
|
|
72
|
+
]);
|
|
73
|
+
const importBuildFileContentFixed = importBuildFileContent.replace(ASSETS_MAP, assetsJsonString);
|
|
74
|
+
(0, utils_js_1.assert)(importBuildFileContentFixed !== importBuildFileContent);
|
|
75
|
+
await promises_1.default.writeFile(importBuildFilePath, importBuildFileContentFixed);
|
|
76
|
+
}
|
|
77
|
+
function getImportPath(config) {
|
|
78
|
+
// We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
|
|
79
|
+
const filePathAbsolute = (0, utils_js_1.toPosixPath)(
|
|
80
|
+
// [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/importBuild/index.js
|
|
81
|
+
require_.resolve(`../../../../../../dist/esm/node/runtime/globalContext/loadImportBuild.js`));
|
|
82
|
+
if (
|
|
83
|
+
// Let's implement a new config if a user needs the import to be a relative path instead of 'vike/__internal/loadImportBuild' (AFAIK a relative path is needed only if a framework has npm package 'vike' as direct dependency instead of a peer dependency and if the user of that framework uses pnpm)
|
|
84
|
+
true) {
|
|
85
|
+
return 'vike/__internal/loadImportBuild';
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const { outDirServer } = (0, utils_js_1.getOutDirs)(config);
|
|
89
|
+
const filePathRelative = path_1.default.posix.relative(outDirServer, filePathAbsolute);
|
|
90
|
+
return filePathRelative;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -37,6 +37,9 @@ const configDefinitionsBuiltIn = {
|
|
|
37
37
|
guard: {
|
|
38
38
|
env: { server: true, client: 'if-client-routing' }
|
|
39
39
|
},
|
|
40
|
+
data: {
|
|
41
|
+
env: { server: true }
|
|
42
|
+
},
|
|
40
43
|
iKnowThePerformanceRisksOfAsyncRouteFunctions: {
|
|
41
44
|
env: { server: true, client: 'if-client-routing', eager: true }
|
|
42
45
|
},
|
|
@@ -77,6 +80,10 @@ const configDefinitionsBuiltIn = {
|
|
|
77
80
|
env: { client: true },
|
|
78
81
|
_computed: (configValueSources) => !isConfigSet(configValueSources, 'onBeforeRender') ? null : getConfigEnv(configValueSources, 'onBeforeRender')
|
|
79
82
|
},
|
|
83
|
+
dataEnv: {
|
|
84
|
+
env: { client: true },
|
|
85
|
+
_computed: (configValueSources) => !isConfigSet(configValueSources, 'data') ? null : getConfigEnv(configValueSources, 'data')
|
|
86
|
+
},
|
|
80
87
|
hooksTimeout: {
|
|
81
88
|
env: { server: true, client: true }
|
|
82
89
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -10,22 +10,23 @@ const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
|
10
10
|
const child_process_1 = require("child_process");
|
|
11
11
|
const util_1 = require("util");
|
|
12
12
|
const execA = (0, util_1.promisify)(child_process_1.exec);
|
|
13
|
+
const globalObject = (0, utils_js_1.getGlobalObject)('crawlPlusFiles.ts', {
|
|
14
|
+
gitIsMissing: false
|
|
15
|
+
});
|
|
13
16
|
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
14
17
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
15
18
|
(0, utils_js_1.assertPosixPath)(outDirAbsoluteFilesystem);
|
|
16
|
-
// Vike prepends userRootDir without resolving, e.g. outDirRelativeFromUserRootDir can be /home/rom/my-monorepo/my-app/../my-build/dist/ while userRootDir is /home/rom/my-monorepo/my-app/
|
|
17
|
-
(0, utils_js_1.assert)(outDirAbsoluteFilesystem.startsWith(userRootDir));
|
|
18
19
|
let outDirRelativeFromUserRootDir = path_1.default.posix.relative(userRootDir, outDirAbsoluteFilesystem);
|
|
19
20
|
if (outDirRelativeFromUserRootDir.startsWith('../')) {
|
|
20
21
|
// config.outDir is outside of config.root => it's going to be ignored anyways
|
|
21
22
|
outDirRelativeFromUserRootDir = null;
|
|
22
23
|
}
|
|
23
24
|
(0, utils_js_1.assert)(outDirRelativeFromUserRootDir === null || !outDirRelativeFromUserRootDir.startsWith('.'));
|
|
24
|
-
const
|
|
25
|
+
const timeBefore = new Date().getTime();
|
|
25
26
|
let files = [];
|
|
26
27
|
const res = await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir);
|
|
27
28
|
if (res &&
|
|
28
|
-
// Fallback to fast-glob for users that dynamically generate plus files (
|
|
29
|
+
// Fallback to fast-glob for users that dynamically generate plus files. (Assuming all (generetad) plus files to be skipped because users usually included them in `.gitignore`.)
|
|
29
30
|
res.length > 0) {
|
|
30
31
|
files = res;
|
|
31
32
|
}
|
|
@@ -33,10 +34,11 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
33
34
|
files = await fastGlob(userRootDir, outDirRelativeFromUserRootDir);
|
|
34
35
|
}
|
|
35
36
|
{
|
|
36
|
-
const
|
|
37
|
+
const timeAfter = new Date().getTime();
|
|
38
|
+
const timeSpent = timeAfter - timeBefore;
|
|
37
39
|
if (isDev) {
|
|
38
|
-
// We only warn in dev, because while building it's expected to take a long time as
|
|
39
|
-
(0, utils_js_1.assertWarning)(
|
|
40
|
+
// We only warn in dev, because while building it's expected to take a long time as crawling is competing for resources with other tasks.
|
|
41
|
+
(0, utils_js_1.assertWarning)(timeSpent < 2 * 1000, `Crawling your user files took an unexpected long time (${timeSpent}ms). Create a new issue on Vike's GitHub.`, {
|
|
40
42
|
onlyOnce: 'slow-page-files-search'
|
|
41
43
|
});
|
|
42
44
|
}
|
|
@@ -56,37 +58,54 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev) {
|
|
|
56
58
|
exports.crawlPlusFiles = crawlPlusFiles;
|
|
57
59
|
// Same as fastGlob() but using `$ git ls-files`
|
|
58
60
|
async function gitLsFiles(userRootDir, outDirRelativeFromUserRootDir) {
|
|
59
|
-
if (
|
|
61
|
+
if (globalObject.gitIsMissing)
|
|
60
62
|
return null;
|
|
63
|
+
const ignoreAsPatterns = getIgnoreAsPatterns(outDirRelativeFromUserRootDir);
|
|
64
|
+
const ignoreAsFilterFn = getIgnoreAsFilterFn(outDirRelativeFromUserRootDir);
|
|
61
65
|
const cmd = [
|
|
62
66
|
'git ls-files',
|
|
63
67
|
...utils_js_1.scriptFileExtensionList.map((ext) => `"**/+*.${ext}"`),
|
|
64
|
-
...
|
|
68
|
+
...ignoreAsPatterns.map((pattern) => `--exclude="${pattern}"`),
|
|
65
69
|
// --others lists untracked files only (but using .gitignore because --exclude-standard)
|
|
66
70
|
// --cached adds the tracked files to the output
|
|
67
71
|
'--others --cached --exclude-standard'
|
|
68
72
|
].join(' ');
|
|
69
|
-
let files
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
let files;
|
|
74
|
+
let filesDeleted;
|
|
75
|
+
try {
|
|
76
|
+
;
|
|
77
|
+
[files, filesDeleted] = await Promise.all([
|
|
78
|
+
// Main command
|
|
79
|
+
runCmd(cmd, userRootDir),
|
|
80
|
+
// Get tracked by deleted files
|
|
81
|
+
runCmd('git ls-files --deleted', userRootDir)
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
if (await isGitMissing(userRootDir)) {
|
|
86
|
+
globalObject.gitIsMissing = true;
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
throw err;
|
|
90
|
+
}
|
|
91
|
+
files = files
|
|
92
|
+
// We have to repeat the same exclusion logic here because the `git ls-files` option --exclude only applies to untracked files. (We use --exclude only to speed up the command.)
|
|
93
|
+
.filter(ignoreAsFilterFn)
|
|
94
|
+
.filter((file) => !filesDeleted.includes(file));
|
|
76
95
|
return files;
|
|
77
96
|
}
|
|
78
97
|
// Same as gitLsFiles() but using fast-glob
|
|
79
98
|
async function fastGlob(userRootDir, outDirRelativeFromUserRootDir) {
|
|
80
99
|
const files = await (0, fast_glob_1.default)(`**/+*.${utils_js_1.scriptFileExtensions}`, {
|
|
81
|
-
ignore:
|
|
100
|
+
ignore: getIgnoreAsPatterns(outDirRelativeFromUserRootDir),
|
|
82
101
|
cwd: userRootDir,
|
|
83
102
|
dot: false
|
|
84
103
|
});
|
|
85
104
|
return files;
|
|
86
105
|
}
|
|
87
106
|
// Same as getIgnoreFilter() but as glob pattern
|
|
88
|
-
function
|
|
89
|
-
const
|
|
107
|
+
function getIgnoreAsPatterns(outDirRelativeFromUserRootDir) {
|
|
108
|
+
const ignoreAsPatterns = [
|
|
90
109
|
'**/node_modules/**',
|
|
91
110
|
// Allow:
|
|
92
111
|
// ```
|
|
@@ -97,31 +116,30 @@ function getIgnorePatterns(outDirRelativeFromUserRootDir) {
|
|
|
97
116
|
];
|
|
98
117
|
if (outDirRelativeFromUserRootDir) {
|
|
99
118
|
(0, utils_js_1.assert)(!outDirRelativeFromUserRootDir.startsWith('/'));
|
|
100
|
-
|
|
119
|
+
ignoreAsPatterns.push(`${outDirRelativeFromUserRootDir}/**`);
|
|
101
120
|
}
|
|
102
|
-
return
|
|
121
|
+
return ignoreAsPatterns;
|
|
103
122
|
}
|
|
104
123
|
// Same as getIgnorePatterns() but for Array.filter()
|
|
105
|
-
function
|
|
106
|
-
(0, utils_js_1.assert)(!file.startsWith('/'));
|
|
124
|
+
function getIgnoreAsFilterFn(outDirRelativeFromUserRootDir) {
|
|
107
125
|
(0, utils_js_1.assert)(outDirRelativeFromUserRootDir === null || !outDirRelativeFromUserRootDir.startsWith('/'));
|
|
108
|
-
return (!file.includes('node_modules/') &&
|
|
126
|
+
return (file) => !file.includes('node_modules/') &&
|
|
109
127
|
!file.includes('.telefunc.') &&
|
|
110
|
-
(
|
|
128
|
+
(outDirRelativeFromUserRootDir === null || !file.startsWith(`${outDirRelativeFromUserRootDir}/`));
|
|
111
129
|
}
|
|
112
130
|
// Whether Git is installed and whether userRootDir is inside a Git repository
|
|
113
|
-
async function
|
|
131
|
+
async function isGitMissing(userRootDir) {
|
|
114
132
|
let res;
|
|
115
133
|
try {
|
|
116
134
|
res = await execA('git rev-parse --is-inside-work-tree', { cwd: userRootDir });
|
|
117
135
|
}
|
|
118
136
|
catch {
|
|
119
|
-
return
|
|
137
|
+
return true;
|
|
120
138
|
}
|
|
121
139
|
const { stdout, stderr } = res;
|
|
122
140
|
(0, utils_js_1.assert)(stderr.toString().trim() === '');
|
|
123
141
|
(0, utils_js_1.assert)(stdout.toString().trim() === 'true');
|
|
124
|
-
return
|
|
142
|
+
return false;
|
|
125
143
|
}
|
|
126
144
|
async function runCmd(cmd, cwd) {
|
|
127
145
|
const res = await execA(cmd, { cwd });
|