vike 0.4.161 → 0.4.162-commit-8995471
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/__internal/index.js +2 -2
- package/dist/cjs/node/plugin/index.js +0 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +41 -37
- package/dist/cjs/node/plugin/plugins/config/index.js +2 -7
- package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -8
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -18
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +2 -4
- package/dist/cjs/node/plugin/plugins/envVars.js +6 -2
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +10 -22
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +1 -21
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +29 -95
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +8 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +1 -9
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +4 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +35 -36
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +109 -104
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +39 -33
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +0 -14
- package/dist/cjs/node/plugin/shared/rollupSourceMap.js +20 -0
- package/dist/cjs/node/plugin/utils.js +0 -1
- package/dist/cjs/node/prerender/runPrerender.js +3 -2
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +8 -19
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +1 -0
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +2 -8
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +23 -28
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -23
- package/dist/cjs/node/runtime/utils.js +1 -2
- package/dist/cjs/node/shared/assertPluginManifest.js +1 -4
- package/dist/cjs/node/shared/assertV1Design.js +26 -0
- package/dist/cjs/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +3 -3
- package/dist/cjs/node/shared/prependEntriesDir.js +13 -0
- package/dist/cjs/node/shared/utils.js +2 -0
- package/dist/cjs/node/shared/virtual-files/virtualFileImportUserCode.js +1 -0
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +1 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
- package/dist/cjs/shared/route/abort.js +1 -0
- package/dist/cjs/shared/route/resolvePrecedence.js +1 -0
- package/dist/cjs/utils/{nodeEnv.js → assertNodeEnv.js} +3 -0
- package/dist/cjs/utils/formatHintLog.js +1 -0
- package/dist/cjs/utils/hasProp.js +1 -0
- package/dist/cjs/utils/isScriptFile.js +15 -4
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/__internal/index.js +1 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +20 -14
- package/dist/esm/client/shared/getPageContextProxyForUser.js +19 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.js +1 -0
- package/dist/esm/node/plugin/index.js +0 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +40 -36
- package/dist/esm/node/plugin/plugins/config/index.js +2 -7
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +1 -8
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -19
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -4
- package/dist/esm/node/plugin/plugins/envVars.js +6 -2
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +11 -23
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -19
- package/dist/esm/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +31 -97
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +8 -8
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +1 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.d.ts +1 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js +35 -36
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +111 -106
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +39 -33
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +1 -15
- package/dist/esm/node/plugin/shared/rollupSourceMap.d.ts +14 -0
- package/dist/esm/node/plugin/shared/rollupSourceMap.js +17 -0
- package/dist/esm/node/plugin/utils.d.ts +0 -1
- package/dist/esm/node/plugin/utils.js +0 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +3 -3
- package/dist/esm/node/prerender/runPrerender.js +4 -3
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +3 -10
- package/dist/esm/node/runtime/globalContext.js +7 -18
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +1 -0
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +2 -8
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +24 -29
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -24
- package/dist/esm/node/runtime/utils.d.ts +1 -2
- package/dist/esm/node/runtime/utils.js +1 -2
- package/dist/esm/node/shared/ViteManifest.d.ts +1 -0
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertPluginManifest.js +2 -5
- package/dist/esm/node/shared/assertV1Design.d.ts +4 -0
- package/dist/esm/node/shared/assertV1Design.js +23 -0
- package/dist/esm/node/shared/getClientEntry.d.ts +3 -0
- package/dist/esm/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +2 -2
- package/dist/esm/node/shared/prependEntriesDir.d.ts +2 -0
- package/dist/esm/node/shared/prependEntriesDir.js +10 -0
- package/dist/esm/node/shared/utils.d.ts +2 -0
- package/dist/esm/node/shared/utils.js +2 -0
- package/dist/esm/node/shared/virtual-files/virtualFileImportUserCode.js +1 -0
- package/dist/esm/shared/ConfigVike.d.ts +0 -27
- package/dist/esm/shared/hooks/getHook.js +2 -2
- package/dist/esm/shared/page-configs/Config.d.ts +5 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -4
- package/dist/esm/shared/page-configs/helpers/getConfigValue.js +1 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
- package/dist/esm/shared/route/abort.js +1 -0
- package/dist/esm/shared/route/resolvePrecedence.js +1 -0
- package/dist/esm/utils/{nodeEnv.js → assertNodeEnv.js} +3 -0
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/formatHintLog.js +1 -0
- package/dist/esm/utils/hasProp.js +1 -0
- package/dist/esm/utils/isScriptFile.d.ts +3 -1
- package/dist/esm/utils/isScriptFile.js +14 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +4 -3
- package/dist/cjs/node/plugin/plugins/config/findConfigVikeFromStemPackages.js +0 -27
- package/dist/cjs/node/plugin/plugins/config/resolveExtensions.js +0 -107
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +0 -85
- package/dist/cjs/node/plugin/plugins/extensionsAssets.js +0 -101
- package/dist/cjs/node/plugin/shared/removeSourceMap.js +0 -12
- package/dist/cjs/utils/getDependencyPackageJson.js +0 -91
- package/dist/cjs/utils/isStemPackageName.js +0 -14
- package/dist/esm/node/plugin/plugins/config/findConfigVikeFromStemPackages.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/config/findConfigVikeFromStemPackages.js +0 -24
- package/dist/esm/node/plugin/plugins/config/resolveExtensions.d.ts +0 -4
- package/dist/esm/node/plugin/plugins/config/resolveExtensions.js +0 -101
- package/dist/esm/node/plugin/plugins/config/stemUtils.d.ts +0 -8
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +0 -79
- package/dist/esm/node/plugin/plugins/extensionsAssets.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/extensionsAssets.js +0 -95
- package/dist/esm/node/plugin/shared/removeSourceMap.d.ts +0 -7
- package/dist/esm/node/plugin/shared/removeSourceMap.js +0 -9
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +0 -3
- package/dist/esm/utils/getDependencyPackageJson.d.ts +0 -6
- package/dist/esm/utils/getDependencyPackageJson.js +0 -85
- package/dist/esm/utils/isStemPackageName.d.ts +0 -1
- package/dist/esm/utils/isStemPackageName.js +0 -10
- /package/dist/esm/utils/{nodeEnv.d.ts → assertNodeEnv.d.ts} +0 -0
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isStemPackageName = void 0;
|
|
4
|
-
function isStemPackageName(npmPackageName) {
|
|
5
|
-
if (npmPackageName.startsWith('stem-')) {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
const [orgName, pkgName] = npmPackageName.split('/');
|
|
9
|
-
if (orgName.startsWith('@') && pkgName?.startsWith('stem-')) {
|
|
10
|
-
return true;
|
|
11
|
-
}
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
exports.isStemPackageName = isStemPackageName;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export { findConfigVikeFromStemPackages };
|
|
2
|
-
import { assert, createDebugger, isObject } from '../../utils.js';
|
|
3
|
-
import { getStemPackages } from './stemUtils.js';
|
|
4
|
-
const debug = createDebugger('vike:stem');
|
|
5
|
-
async function findConfigVikeFromStemPackages(root) {
|
|
6
|
-
if (isDeno())
|
|
7
|
-
return [];
|
|
8
|
-
const stemPackages = await getStemPackages(root);
|
|
9
|
-
const configVikeFromStemPackages = [];
|
|
10
|
-
debug('Stem packages found:', stemPackages.map(({ stemPackageName, stemPackageRootDir }) => ({ stemPackageName, stemPackageRootDir })));
|
|
11
|
-
await Promise.all(stemPackages.map(async ({ loadModule }) => {
|
|
12
|
-
const moduleExports = (await loadModule('vike.config.js')) || (await loadModule('vite-plugin-ssr.config.js'));
|
|
13
|
-
if (!moduleExports)
|
|
14
|
-
return;
|
|
15
|
-
const configVike = moduleExports.default;
|
|
16
|
-
assert(isObject(configVike));
|
|
17
|
-
configVikeFromStemPackages.push(configVike);
|
|
18
|
-
}));
|
|
19
|
-
return configVikeFromStemPackages;
|
|
20
|
-
}
|
|
21
|
-
function isDeno() {
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
return typeof Deno !== 'undefined' && Deno.env;
|
|
24
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { resolveExtensions };
|
|
2
|
-
import type { ResolvedConfig } from 'vite';
|
|
3
|
-
import type { ConfigVikeUserProvided, ExtensionResolved } from '../../../../shared/ConfigVike.js';
|
|
4
|
-
declare function resolveExtensions(configs: ConfigVikeUserProvided[], config: ResolvedConfig): ExtensionResolved[];
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
export { resolveExtensions };
|
|
2
|
-
import { assert, assertUsage, getNpmPackageName, toPosixPath, isNpmPackageName, getDependencyRootDir, assertPosixPath } from '../../utils.js';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import { isValidFileType } from '../../../../shared/getPageFiles/fileTypes.js';
|
|
6
|
-
import { createRequire } from 'module';
|
|
7
|
-
import pc from '@brillout/picocolors';
|
|
8
|
-
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
9
|
-
const importMetaUrl = import.meta.url;
|
|
10
|
-
const require_ = createRequire(importMetaUrl);
|
|
11
|
-
function resolveExtensions(configs, config) {
|
|
12
|
-
const extensions = configs.map((c) => c.extensions ?? []).flat();
|
|
13
|
-
return extensions.map((extension) => {
|
|
14
|
-
const { npmPackageName } = extension;
|
|
15
|
-
assertUsage(isNpmPackageName(npmPackageName), `vike extension ${pc.cyan(npmPackageName)} doesn't seem to be a valid npm package name`);
|
|
16
|
-
const npmPackageRootDir = getDependencyRootDir(npmPackageName, config.root);
|
|
17
|
-
assertPosixPath(npmPackageRootDir);
|
|
18
|
-
const pageConfigsDistFiles = resolvePageFilesDist([
|
|
19
|
-
...(extension.pageConfigsDistFiles ?? []),
|
|
20
|
-
// TODO/v1-release: remove
|
|
21
|
-
...(extension.pageFilesDist ?? [])
|
|
22
|
-
], npmPackageName, config, npmPackageRootDir);
|
|
23
|
-
let pageConfigsSrcDirResolved = null;
|
|
24
|
-
{
|
|
25
|
-
const pageConfigsSrcDir = extension.pageConfigsSrcDir ?? extension.pageFilesSrc;
|
|
26
|
-
if (pageConfigsSrcDir) {
|
|
27
|
-
assertPathProvidedByUser('pageConfigsSrcDir', pageConfigsSrcDir, true);
|
|
28
|
-
assert(pageConfigsSrcDir.endsWith('*'));
|
|
29
|
-
pageConfigsSrcDirResolved = path.posix.join(npmPackageRootDir, pageConfigsSrcDir.slice(0, -1));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
assertUsage(pageConfigsSrcDirResolved || pageConfigsDistFiles, `Extension ${npmPackageName} should define either extension[number].pageConfigsDistFiles or extension[number].pageConfigsSrcDir`);
|
|
33
|
-
assertUsage(!pageConfigsDistFiles || !pageConfigsSrcDirResolved, `Extension ${npmPackageName} shouldn't define extension[number].pageConfigsDistFiles as well extension[number].pageConfigsSrcDir, it should define only one instead`);
|
|
34
|
-
const assetsDir = (() => {
|
|
35
|
-
if (!extension.assetsDir) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
assertPathProvidedByUser('assetsDir', extension.assetsDir);
|
|
39
|
-
assertPosixPath(extension.assetsDir);
|
|
40
|
-
const assetsDir = path.posix.join(npmPackageRootDir, extension.assetsDir);
|
|
41
|
-
return assetsDir;
|
|
42
|
-
})();
|
|
43
|
-
assertUsage(!(assetsDir && pageConfigsSrcDirResolved), `Extension ${npmPackageName} shouldn't define both extension[number].pageConfigsSrcDir and extension[number].assetsDir`);
|
|
44
|
-
const extensionResolved = {
|
|
45
|
-
npmPackageName,
|
|
46
|
-
npmPackageRootDir,
|
|
47
|
-
pageConfigsDistFiles,
|
|
48
|
-
pageConfigsSrcDir: pageConfigsSrcDirResolved,
|
|
49
|
-
assetsDir
|
|
50
|
-
};
|
|
51
|
-
return extensionResolved;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function assertPathProvidedByUser(pathName, pathValue, starSuffix) {
|
|
55
|
-
const errMsg = `extension[number].${pathName} value ${pc.cyan(pathValue)}`;
|
|
56
|
-
assertUsage(!pathValue.includes('\\'), `${errMsg} shouldn't contain any backward slahes '\' (replace them with forward slahes '/')`);
|
|
57
|
-
assertUsage(!starSuffix || pathValue.endsWith('/*'), `${errMsg} should end with '/*'`);
|
|
58
|
-
assertUsage(pathValue.startsWith('/'), `${errMsg} should start with '/'`);
|
|
59
|
-
}
|
|
60
|
-
function resolvePageFilesDist(pageConfigsDistFiles, npmPackageName, config, npmPackageRootDir) {
|
|
61
|
-
if (!pageConfigsDistFiles || pageConfigsDistFiles.length === 0)
|
|
62
|
-
return null;
|
|
63
|
-
const pageConfigsDistFilesResolved = [];
|
|
64
|
-
pageConfigsDistFiles.forEach((importPath) => {
|
|
65
|
-
const errPrefix = `The page file ${pc.cyan(importPath)} (provided in extensions[number].pageFiles) should`;
|
|
66
|
-
assertUsage(npmPackageName === getNpmPackageName(importPath), `${errPrefix} be a ${pc.cyan(npmPackageName)} module (e.g. ${pc.cyan(`${npmPackageName}/renderer/_default.page.server.js`)})`);
|
|
67
|
-
assertUsage(isValidFileType(importPath), `${errPrefix} end with '.js', '.js', '.cjs', or '.css'`);
|
|
68
|
-
const filePath = resolveImportPath(importPath, npmPackageName, config, npmPackageRootDir);
|
|
69
|
-
pageConfigsDistFilesResolved.push({
|
|
70
|
-
importPath,
|
|
71
|
-
filePath
|
|
72
|
-
});
|
|
73
|
-
const filePathCSS = getPathCSS(filePath);
|
|
74
|
-
if (filePathCSS !== filePath && fs.existsSync(filePathCSS)) {
|
|
75
|
-
const importPathCSS = getPathCSS(importPath);
|
|
76
|
-
assertUsage(filePathCSS === resolveImportPath(importPathCSS, npmPackageName, config, npmPackageRootDir), `The entry package.json#exports["${importPathCSS}"] in the package.json of ${npmPackageName} (${npmPackageRootDir}/package.json) has a wrong value: make sure it resolves to ${filePathCSS}`);
|
|
77
|
-
pageConfigsDistFilesResolved.push({
|
|
78
|
-
importPath: importPathCSS,
|
|
79
|
-
filePath: filePathCSS
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
return pageConfigsDistFilesResolved;
|
|
84
|
-
}
|
|
85
|
-
function resolveImportPath(importPath, npmPackageName, config, npmPackageRootDir) {
|
|
86
|
-
let filePath;
|
|
87
|
-
try {
|
|
88
|
-
filePath = require_.resolve(importPath, { paths: [config.root] });
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
if (err?.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
|
|
92
|
-
assertUsage(false, `Define ${importPath} in the package.json#exports of ${npmPackageName} (${npmPackageRootDir}/package.json) with a Node.js export condition (even if it's a browser file such as CSS)`);
|
|
93
|
-
}
|
|
94
|
-
throw err;
|
|
95
|
-
}
|
|
96
|
-
filePath = toPosixPath(filePath);
|
|
97
|
-
return filePath;
|
|
98
|
-
}
|
|
99
|
-
function getPathCSS(filePath) {
|
|
100
|
-
return filePath.split('.').slice(0, -1).join('.') + '.css';
|
|
101
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { getStemPackages };
|
|
2
|
-
export type { StemPackage };
|
|
3
|
-
type StemPackage = {
|
|
4
|
-
stemPackageName: string;
|
|
5
|
-
stemPackageRootDir: string;
|
|
6
|
-
loadModule: (moduleId: string) => Promise<null | Record<string, unknown>>;
|
|
7
|
-
};
|
|
8
|
-
declare function getStemPackages(userAppRootDir: string): Promise<StemPackage[]>;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// Move to standalone package? E.g. https://www.npmjs.com/package/stem
|
|
2
|
-
export { getStemPackages };
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { assert, assertUsage, assertWarning, toPosixPath, assertPosixPath, getDependencyRootDir, findFile } from '../../utils.js';
|
|
5
|
-
import { import_ } from '@brillout/import';
|
|
6
|
-
import { createRequire } from 'module';
|
|
7
|
-
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
8
|
-
const importMetaUrl = import.meta.url;
|
|
9
|
-
const require_ = createRequire(importMetaUrl);
|
|
10
|
-
async function getStemPackages(userAppRootDir) {
|
|
11
|
-
const userRootDir = findUserRootDir(userAppRootDir);
|
|
12
|
-
const userPkgJson = getUserPackageJson(userRootDir);
|
|
13
|
-
const stemPkgNames = getStemPkgNames(userPkgJson);
|
|
14
|
-
const stemPackages = await Promise.all(stemPkgNames.map((stemPackageName) => {
|
|
15
|
-
assert(stemPackageName.includes('stem-'));
|
|
16
|
-
const resolveModulePath = (moduleId) => {
|
|
17
|
-
const importPath = `${stemPackageName}/${moduleId}`;
|
|
18
|
-
try {
|
|
19
|
-
const modulePath = require_.resolve(importPath, { paths: [userRootDir] });
|
|
20
|
-
return modulePath;
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
// - ERR_PACKAGE_PATH_NOT_EXPORTED => package.json#exports[importPath] is missing
|
|
24
|
-
// - We assert that Stem packages always define package.json#exports down below
|
|
25
|
-
if (err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
// All other errors such as ERR_MODULE_NOT_FOUND should be thrown
|
|
29
|
-
throw err;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const loadModule = async (moduleId) => {
|
|
33
|
-
const modulePath = resolveModulePath(moduleId);
|
|
34
|
-
if (modulePath === null)
|
|
35
|
-
return null;
|
|
36
|
-
const moduleExports = moduleId.endsWith('.json')
|
|
37
|
-
? require_(modulePath)
|
|
38
|
-
: await import_(modulePath);
|
|
39
|
-
return moduleExports;
|
|
40
|
-
};
|
|
41
|
-
const stemPackageRootDir = getDependencyRootDir(stemPackageName, userAppRootDir);
|
|
42
|
-
return {
|
|
43
|
-
stemPackageName,
|
|
44
|
-
stemPackageRootDir,
|
|
45
|
-
loadModule
|
|
46
|
-
};
|
|
47
|
-
}));
|
|
48
|
-
return stemPackages;
|
|
49
|
-
}
|
|
50
|
-
function findUserRootDir(userAppRootDir) {
|
|
51
|
-
const userPkgJsonPath = findFile('package.json', userAppRootDir);
|
|
52
|
-
assertUsage(userPkgJsonPath, `Couldn't find package.json in any parent directory starting from ${userAppRootDir}`);
|
|
53
|
-
return toPosixPath(path.dirname(userPkgJsonPath));
|
|
54
|
-
}
|
|
55
|
-
function getStemPkgNames(userPkgJson) {
|
|
56
|
-
const stemPkgNames = Object.keys(userPkgJson.dependencies ?? {}).filter((depName) => {
|
|
57
|
-
if (depName.startsWith('stem-')) {
|
|
58
|
-
assertWarning(false, `${depName} should be renamed to @someNpmOrgOrUser/${depName} (to follow the convention that all Stem packages belond to an npm organization)`, { onlyOnce: true });
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
if (depName.split('/')[1]?.startsWith('stem-')) {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
return false;
|
|
65
|
-
});
|
|
66
|
-
return stemPkgNames;
|
|
67
|
-
}
|
|
68
|
-
function getUserPackageJson(userRootDir) {
|
|
69
|
-
assertPosixPath(userRootDir);
|
|
70
|
-
const userPkgJsonPath = path.posix.join(userRootDir, './package.json');
|
|
71
|
-
let userPkgJson;
|
|
72
|
-
try {
|
|
73
|
-
userPkgJson = require_(userPkgJsonPath);
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
throw new Error(`No package.json found at ${userRootDir}`);
|
|
77
|
-
}
|
|
78
|
-
return userPkgJson;
|
|
79
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
export { extensionsAssets };
|
|
2
|
-
import { assert, isScriptFile, assertUsage, assertPosixPath, getOutDirs } from '../utils.js';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import sirv from 'sirv';
|
|
6
|
-
import { getConfigVike } from '../../shared/getConfigVike.js';
|
|
7
|
-
import { isAsset } from '../shared/isAsset.js';
|
|
8
|
-
const ASSET_DIR = 'assets';
|
|
9
|
-
function extensionsAssets() {
|
|
10
|
-
let config;
|
|
11
|
-
let extensionsAssetsDir;
|
|
12
|
-
return {
|
|
13
|
-
name: 'vike:extensionsAssets',
|
|
14
|
-
async configResolved(config_) {
|
|
15
|
-
config = config_;
|
|
16
|
-
const configVike = await getConfigVike(config);
|
|
17
|
-
extensionsAssetsDir = getExtensionsAssetsDir(config, configVike);
|
|
18
|
-
},
|
|
19
|
-
configureServer(server) {
|
|
20
|
-
if (extensionsAssetsDir.length > 0) {
|
|
21
|
-
return () => {
|
|
22
|
-
serveExtensionsAssets(server.middlewares, extensionsAssetsDir, config);
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
writeBundle() {
|
|
27
|
-
if (!config.build.ssr && extensionsAssetsDir.length > 0) {
|
|
28
|
-
copyExtensionsAssetsDir(config, extensionsAssetsDir);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function serveExtensionsAssets(middlewares, extensionsAssetsDirs, config) {
|
|
34
|
-
assert(ASSET_DIR === getAsssetsDirConfig(config));
|
|
35
|
-
extensionsAssetsDirs.forEach((assetsDir) => {
|
|
36
|
-
const serve = sirv(assetsDir);
|
|
37
|
-
middlewares.use(async (req, res, next) => {
|
|
38
|
-
if (!req.url?.startsWith(`/${ASSET_DIR}/`)) {
|
|
39
|
-
next();
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// https://github.com/lukeed/sirv/issues/148 - [Feature Request] New option base.
|
|
43
|
-
req.url = '/' + req.url.slice(`/${ASSET_DIR}/`.length);
|
|
44
|
-
serve(req, res, next);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function getExtensionsAssetsDir(config, configVike) {
|
|
49
|
-
const { extensions } = configVike;
|
|
50
|
-
const extensionsWithAssetsDir = extensions.filter(({ assetsDir }) => assetsDir);
|
|
51
|
-
if (0 === extensionsWithAssetsDir.length)
|
|
52
|
-
return [];
|
|
53
|
-
assertUsage(ASSET_DIR === getAsssetsDirConfig(config), 'Cannot modify vite.config.js#build.assetsDir while using ' + extensionsWithAssetsDir[0].npmPackageName);
|
|
54
|
-
const extensionsAssetsDir = extensionsWithAssetsDir.map(({ assetsDir }) => {
|
|
55
|
-
assert(assetsDir);
|
|
56
|
-
assertPosixPath(assetsDir);
|
|
57
|
-
return assetsDir;
|
|
58
|
-
});
|
|
59
|
-
return extensionsAssetsDir;
|
|
60
|
-
}
|
|
61
|
-
function getAsssetsDirConfig(config) {
|
|
62
|
-
let { assetsDir } = config.build;
|
|
63
|
-
assertPosixPath(assetsDir);
|
|
64
|
-
assetsDir = assetsDir.split('/').filter(Boolean).join('/');
|
|
65
|
-
return assetsDir;
|
|
66
|
-
}
|
|
67
|
-
function copyExtensionsAssetsDir(config, extensionsAssetsDirs) {
|
|
68
|
-
assert(ASSET_DIR === getAsssetsDirConfig(config));
|
|
69
|
-
const { outDirClient } = getOutDirs(config);
|
|
70
|
-
assertPosixPath(outDirClient);
|
|
71
|
-
const outDirAssets = path.posix.join(outDirClient, ASSET_DIR);
|
|
72
|
-
extensionsAssetsDirs.forEach((assetsDir) => {
|
|
73
|
-
copyAssetFiles(assetsDir, outDirAssets);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
// Adapted from https://github.com/vitejs/vite/blob/e92d025cedabb477687d6a352ee8c9b7d529f623/packages/vite/src/node/utils.ts#L589-L604
|
|
77
|
-
function copyAssetFiles(srcDir, destDir) {
|
|
78
|
-
let destDirCreated = false;
|
|
79
|
-
for (const file of fs.readdirSync(srcDir)) {
|
|
80
|
-
const srcFile = path.resolve(srcDir, file);
|
|
81
|
-
const destFile = path.resolve(destDir, file);
|
|
82
|
-
const stat = fs.statSync(srcFile);
|
|
83
|
-
if (stat.isDirectory()) {
|
|
84
|
-
copyAssetFiles(srcFile, destFile);
|
|
85
|
-
}
|
|
86
|
-
else if (isAsset(srcFile)) {
|
|
87
|
-
assert(!isScriptFile(srcFile));
|
|
88
|
-
if (!destDirCreated) {
|
|
89
|
-
fs.mkdirSync(destDir, { recursive: true });
|
|
90
|
-
destDirCreated = true;
|
|
91
|
-
}
|
|
92
|
-
fs.copyFileSync(srcFile, destFile);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { getDependencyPackageJson };
|
|
2
|
-
export { getDependencyPackageJsonPath };
|
|
3
|
-
export { getDependencyRootDir };
|
|
4
|
-
declare function getDependencyPackageJson(npmPackageName: string, userAppRootDir: string): Record<string, unknown>;
|
|
5
|
-
declare function getDependencyRootDir(npmPackageName: string, userAppRootDir: string): string;
|
|
6
|
-
declare function getDependencyPackageJsonPath(npmPackageName: string, userAppRootDir: string): string;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
export { getDependencyPackageJson };
|
|
2
|
-
export { getDependencyPackageJsonPath };
|
|
3
|
-
export { getDependencyRootDir };
|
|
4
|
-
// There doesn't seem to be any alternative:
|
|
5
|
-
// - https://github.com/antfu/local-pkg
|
|
6
|
-
// - https://stackoverflow.com/questions/74640378/find-and-read-package-json-of-a-dependency
|
|
7
|
-
// - https://stackoverflow.com/questions/58442451/finding-the-root-directory-of-a-dependency-in-npm
|
|
8
|
-
// - https://stackoverflow.com/questions/10111163/how-can-i-get-the-path-of-a-module-i-have-loaded-via-require-that-is-not-mine/63441056#63441056
|
|
9
|
-
import { assert, assertUsage } from './assert.js';
|
|
10
|
-
import { isNpmPackageName } from './isNpmPackage.js';
|
|
11
|
-
import { toPosixPath } from './filesystemPathHandling.js';
|
|
12
|
-
import { isObject } from './isObject.js';
|
|
13
|
-
import path from 'path';
|
|
14
|
-
import fs from 'fs';
|
|
15
|
-
import { assertIsNotProductionRuntime } from './assertIsNotProductionRuntime.js';
|
|
16
|
-
import { createRequire } from 'module';
|
|
17
|
-
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
18
|
-
const importMetaUrl = import.meta.url;
|
|
19
|
-
const require_ = createRequire(importMetaUrl);
|
|
20
|
-
assertIsNotProductionRuntime();
|
|
21
|
-
function getDependencyPackageJson(npmPackageName, userAppRootDir) {
|
|
22
|
-
const packageJsonPath = getDependencyPackageJsonPath(npmPackageName, userAppRootDir);
|
|
23
|
-
const packageJson = fs.readFileSync(packageJsonPath, 'utf8');
|
|
24
|
-
assert(isObject(packageJson));
|
|
25
|
-
return packageJson;
|
|
26
|
-
}
|
|
27
|
-
function getDependencyRootDir(npmPackageName, userAppRootDir) {
|
|
28
|
-
const rootDir = path.posix.dirname(getDependencyPackageJsonPath(npmPackageName, userAppRootDir));
|
|
29
|
-
return rootDir;
|
|
30
|
-
}
|
|
31
|
-
function getDependencyPackageJsonPath(npmPackageName, userAppRootDir) {
|
|
32
|
-
assert(isNpmPackageName(npmPackageName));
|
|
33
|
-
let packageJsonPath = resolvePackageJsonDirectly(npmPackageName, userAppRootDir);
|
|
34
|
-
if (!packageJsonPath) {
|
|
35
|
-
packageJsonPath = resolvePackageJsonWithMainEntry(npmPackageName, userAppRootDir);
|
|
36
|
-
}
|
|
37
|
-
assertUsage(packageJsonPath, `Cannot read ${npmPackageName}/package.json. Define package.json#exports["./package.json"] with the value "./package.json" in the package.json of ${npmPackageName}.`);
|
|
38
|
-
packageJsonPath = toPosixPath(packageJsonPath);
|
|
39
|
-
assert(packageJsonPath.endsWith('/package.json'), packageJsonPath); // package.json#exports["package.json"] may point to another file than package.json
|
|
40
|
-
return packageJsonPath;
|
|
41
|
-
}
|
|
42
|
-
function resolvePackageJsonDirectly(npmPackageName, userAppRootDir) {
|
|
43
|
-
let packageJsonPath;
|
|
44
|
-
try {
|
|
45
|
-
packageJsonPath = require_.resolve(`${npmPackageName}/package.json`, { paths: [userAppRootDir] });
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
if (isUnexpectedError(err))
|
|
49
|
-
throw err;
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
return packageJsonPath;
|
|
53
|
-
}
|
|
54
|
-
function resolvePackageJsonWithMainEntry(npmPackageName, userAppRootDir) {
|
|
55
|
-
let mainEntry;
|
|
56
|
-
try {
|
|
57
|
-
mainEntry = require_.resolve(npmPackageName, { paths: [userAppRootDir] });
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
if (isUnexpectedError(err))
|
|
61
|
-
throw err;
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
const packageJsonPath = searchPackageJSON(mainEntry);
|
|
65
|
-
return packageJsonPath;
|
|
66
|
-
}
|
|
67
|
-
// If the npm package doesn't define package.json#exports then require.resolve(`${npmPackageName}/package.json`) just works.
|
|
68
|
-
// This means we can assume packageJson#exports to be defined and, consequently, we can assume the error code to always be ERR_PACKAGE_PATH_NOT_EXPORTED.
|
|
69
|
-
// (If MODULE_NOT_FOUND is thrown then this means that npmPackageName isn't installed.)
|
|
70
|
-
function isUnexpectedError(err) {
|
|
71
|
-
return err?.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED';
|
|
72
|
-
}
|
|
73
|
-
// Copied and adapted from https://github.com/antfu/local-pkg
|
|
74
|
-
function searchPackageJSON(dir) {
|
|
75
|
-
let packageJsonPath;
|
|
76
|
-
while (true) {
|
|
77
|
-
assert(dir);
|
|
78
|
-
const newDir = path.dirname(dir);
|
|
79
|
-
assert(newDir !== dir);
|
|
80
|
-
dir = newDir;
|
|
81
|
-
packageJsonPath = path.join(dir, 'package.json');
|
|
82
|
-
if (fs.existsSync(packageJsonPath))
|
|
83
|
-
return packageJsonPath;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isStemPackageName(npmPackageName: string): boolean;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export function isStemPackageName(npmPackageName) {
|
|
2
|
-
if (npmPackageName.startsWith('stem-')) {
|
|
3
|
-
return true;
|
|
4
|
-
}
|
|
5
|
-
const [orgName, pkgName] = npmPackageName.split('/');
|
|
6
|
-
if (orgName.startsWith('@') && pkgName?.startsWith('stem-')) {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
File without changes
|