@brillout/vite-plugin-server-entry
Advanced tools
Comparing version
@@ -21,4 +21,3 @@ "use strict"; | ||
const __dirname_ = (0, utils_js_1.toPosixPath)(path_1.default.dirname((0, url_1.fileURLToPath)(importMetaUrl))); | ||
const isCJS = 'require.resolve' === 'require.resolve'; // see dist-cjs-fixup.js | ||
const exportStatement = isCJS ? 'exports.' : 'export const '; | ||
const isCJSEnv = 'require.resolve' === 'require.resolve'; // see dist-cjs-fixup.js | ||
const require_ = (0, module_1.createRequire)(importMetaUrl); | ||
@@ -42,26 +41,62 @@ const autoImporterFilePath = (0, utils_js_1.toPosixPath)(require_.resolve('../runtime/autoImporter.js')); | ||
let config; | ||
let library; | ||
let skip; | ||
const { libraryName } = pluginConfigProvidedByLibrary; | ||
(0, utils_js_1.assert)(libraryName); | ||
let isClientBuild; | ||
let isNotLeaderInstance; | ||
let librariesLength; | ||
const skip = () => { | ||
(0, utils_js_1.assert)('boolean' === typeof isNotLeaderInstance); | ||
(0, utils_js_1.assert)('boolean' === typeof isClientBuild); | ||
return isNotLeaderInstance || isClientBuild; | ||
}; | ||
return [ | ||
{ | ||
name: pluginName, | ||
name: `${pluginName}:config:pre`, | ||
apply: 'build', | ||
// We must run the pre-hook configResolved() of *all* libraries before any post-hook configResolved() hook is called (otherwise isLeaderPluginInstance() will miss libraries and won't work) | ||
enforce: 'pre', | ||
configResolved: { | ||
order: 'pre', | ||
handler(configUnresolved) { | ||
config = resolveConfig(configUnresolved, libraryName, pluginConfigProvidedByLibrary); | ||
(0, utils_js_1.assert)(config._vitePluginServerEntry.libraries.find((l) => l.libraryName === libraryName)); | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: `${pluginName}:config:post`, | ||
apply: 'build', | ||
// We need to run this plugin after other plugin instances, so that assertApiVersions() works also for libraries using older plugin versions | ||
enforce: 'post', | ||
configResolved() { | ||
if (skip) | ||
return; | ||
if (!isLeaderPluginInstance(config, library)) { | ||
skip = true; | ||
return; | ||
} | ||
assertApiVersions(config, pluginConfigProvidedByLibrary.libraryName); | ||
applyPluginConfigProvidedByUser(config); | ||
if (!config._vitePluginServerEntry.disableServerEntryEmit) { | ||
const serverEntryName = getServerEntryName(config); | ||
config.build.rollupOptions.input = (0, utils_js_1.injectRollupInputs)({ [serverEntryName]: serverEntryVirtualId }, config); | ||
} | ||
configResolved: { | ||
order: 'post', | ||
handler() { | ||
(0, utils_js_1.assertUsage)(typeof config.build.ssr !== 'string', "Setting the server build entry over the Vite configuration `build.ssr` (i.e. `--ssr path/to/entry.js`) isn't supported (because of a Vite bug), see workaround at https://github.com/brillout/vite-plugin-server-entry/issues/9#issuecomment-2027641624"); | ||
isClientBuild = !(0, utils_js_1.viteIsSSR)(config); | ||
{ | ||
const prev = librariesLength; | ||
librariesLength = config._vitePluginServerEntry.libraries.length; | ||
(0, utils_js_1.assert)([undefined, librariesLength].includes(prev)); | ||
} | ||
{ | ||
const prev = isNotLeaderInstance; | ||
isNotLeaderInstance = !isLeaderPluginInstance(config, libraryName); | ||
(0, utils_js_1.assert)([undefined, isNotLeaderInstance].includes(prev)); | ||
} | ||
if (skip()) | ||
return; | ||
assertApiVersions(config, pluginConfigProvidedByLibrary.libraryName); | ||
applyPluginConfigProvidedByUser(config); | ||
if (!config._vitePluginServerEntry.disableServerEntryEmit) { | ||
const serverEntryName = getServerEntryName(config); | ||
config.build.rollupOptions.input = (0, utils_js_1.injectRollupInputs)({ [serverEntryName]: serverEntryVirtualId }, config); | ||
} | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: `${pluginName}:hooks`, | ||
apply: 'build', | ||
buildStart() { | ||
if (skip) | ||
if (skip()) | ||
return; | ||
@@ -71,3 +106,3 @@ clearAutoImporter(config); | ||
resolveId(id) { | ||
if (skip) | ||
if (skip()) | ||
return; | ||
@@ -79,3 +114,3 @@ if (id === serverEntryVirtualId) { | ||
load(id) { | ||
if (skip) | ||
if (skip()) | ||
return; | ||
@@ -89,3 +124,3 @@ (0, utils_js_1.assert)(id !== serverEntryVirtualId); | ||
generateBundle(_rollupOptions, bundle) { | ||
if (skip) | ||
if (skip()) | ||
return; | ||
@@ -107,24 +142,26 @@ // Write node_modules/@brillout/vite-plugin-server-entry/dist/autoImporter.js | ||
{ | ||
name: `${pluginName}:config`, | ||
apply: 'build', | ||
// We need to run this plugin before in order to make isLeaderPluginInstance() work | ||
enforce: 'pre', | ||
configResolved(configUnresolved) { | ||
// Upon the server-side build (`$ vite build --ssr`), we need to override the previous `skip` value set by the client-side build (`$ vite build`). | ||
skip = !(0, utils_js_1.viteIsSSR)(configUnresolved); | ||
if (skip) | ||
return; | ||
(0, utils_js_1.assertUsage)(typeof configUnresolved.build.ssr !== 'string', "Setting the server build entry over the Vite configuration `build.ssr` (i.e. `--ssr path/to/entry.js`) isn't supported (because of a Vite bug), see workaround at https://github.com/brillout/vite-plugin-server-entry/issues/9#issuecomment-2027641624"); | ||
const resolved = resolveConfig(configUnresolved, pluginConfigProvidedByLibrary); | ||
config = resolved.config; | ||
library = resolved.library; | ||
}, | ||
}, | ||
{ | ||
name: `${pluginName}:optimizeDeps`, | ||
config() { | ||
if (isCJSEnv) | ||
return; | ||
return { | ||
ssr: { | ||
optimizeDeps: { | ||
// Needed for @cloudflare/vite-plugin | ||
// Needed for @cloudflare/vite-plugin to avoid following error during SSR optimizeDeps scanning: | ||
// ```console | ||
// ✘ [ERROR] Could not resolve "../../../../../../../../../examples/react-full/dist/server/entry.mjs" | ||
// ../../node_modules/.pnpm/@brillout+vite-plugin-server-entry@0.7.9/node_modules/@brillout/vite-plugin-server-entry/dist/esm/runtime/autoImporter.js:3:58: | ||
// 3 │ export const loadServerEntry = async () => { await import("../../../../../../../../../examples/react-full/dist/server/entry.mjs"); }; | ||
// ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
// | ||
// Error: Build failed with 1 error: | ||
// ../../node_modules/.pnpm/@brillout+vite-plugin-server-entry@0.7.9/node_modules/@brillout/vite-plugin-server-entry/dist/esm/runtime/autoImporter.js:3:58: ERROR: Could not resolve "../../../../../../../../../examples/react-full/dist/server/entry.mjs" | ||
// at failureErrorWithLog (/home/rom/code/vike/node_modules/.pnpm/esbuild@0.25.4/node_modules/esbuild/lib/main.js:1463:15) | ||
// at /home/rom/code/vike/node_modules/.pnpm/esbuild@0.25.4/node_modules/esbuild/lib/main.js:924:25 | ||
// at /home/rom/code/vike/node_modules/.pnpm/esbuild@0.25.4/node_modules/esbuild/lib/main.js:1341:9 | ||
// at processTicksAndRejections (node:internal/process/task_queues:105:5) { | ||
// errors: [Getter/Setter], | ||
// warnings: [Getter/Setter] | ||
// } | ||
// ``` | ||
exclude: ['@brillout/vite-plugin-server-entry'], | ||
@@ -138,4 +175,4 @@ }, | ||
} | ||
function resolveConfig(configUnresolved, pluginConfigProvidedByLibrary) { | ||
(0, utils_js_1.assert)((0, utils_js_1.viteIsSSR)(configUnresolved)); | ||
function resolveConfig(configUnresolved, libraryName, pluginConfigProvidedByLibrary) { | ||
(0, utils_js_1.assert)(pluginConfigProvidedByLibrary.libraryName === libraryName); | ||
const pluginConfigResolved = configUnresolved._vitePluginServerEntry ?? { | ||
@@ -148,14 +185,20 @@ libraries: [], | ||
}; | ||
const library = { | ||
(0, utils_js_1.objectAssign)(configUnresolved, { | ||
_vitePluginServerEntry: pluginConfigResolved, | ||
}); | ||
const libraryNew = { | ||
getServerProductionEntry: pluginConfigProvidedByLibrary.getServerProductionEntry, | ||
libraryName: pluginConfigProvidedByLibrary.libraryName, | ||
libraryName, | ||
pluginVersion: utils_js_1.projectInfo.projectVersion, | ||
apiVersion, | ||
}; | ||
pluginConfigResolved.libraries.push(library); | ||
(0, utils_js_1.objectAssign)(configUnresolved, { | ||
_vitePluginServerEntry: pluginConfigResolved, | ||
}); | ||
const libraryFound = pluginConfigResolved.libraries.find((l) => l.libraryName === libraryName); | ||
if (!libraryFound) { | ||
pluginConfigResolved.libraries.push(libraryNew); | ||
} | ||
else { | ||
(0, utils_js_1.assert)((0, utils_js_1.deepEqual)(libraryNew, libraryFound)); | ||
} | ||
const config = configUnresolved; | ||
return { config, library }; | ||
return config; | ||
} | ||
@@ -175,6 +218,7 @@ function applyPluginConfigProvidedByUser(config) { | ||
} | ||
function isLeaderPluginInstance(config, library) { | ||
function isLeaderPluginInstance(config, libraryName) { | ||
const { libraries } = config._vitePluginServerEntry; | ||
const pluginVersionCurrent = utils_js_1.projectInfo.projectVersion; | ||
(0, utils_js_1.assert)(libraries.includes(library)); | ||
const library = libraries.find((l) => l.libraryName === libraryName); | ||
(0, utils_js_1.assert)(library); | ||
const isNotUsingNewestPluginVersion = libraries.some((lib) => { | ||
@@ -216,3 +260,3 @@ // Can be undefined when set by an older @brillout/vite-plugin-dist-importer version | ||
(0, utils_js_1.assert)(!(0, utils_js_1.isYarnPnP)()); | ||
writeAutoImporterFile((autoImporterFilePathResolved) => [ | ||
writeAutoImporterFile((exportStatement, autoImporterFilePathResolved) => [ | ||
`${exportStatement}status = 'SET';`, | ||
@@ -232,8 +276,6 @@ `${exportStatement}pluginVersion = ${JSON.stringify(utils_js_1.projectInfo.projectVersion)};`, | ||
function clearAutoImporter(config) { | ||
if (isAutoImportDisabled(config)) { | ||
if ((0, utils_js_1.isYarnPnP)()) | ||
return; | ||
} | ||
(0, utils_js_1.assert)(!(0, utils_js_1.isYarnPnP)()); | ||
const status = 'BUILDING'; | ||
writeAutoImporterFile(() => [`${exportStatement}status = '${status}';`, ''].join('\n')); | ||
const status = isAutoImportDisabled(config) ? 'DISABLED' : 'BUILDING'; | ||
writeAutoImporterFile((exportStatement) => [`${exportStatement}status = '${status}';`, ''].join('\n')); | ||
} | ||
@@ -359,11 +401,27 @@ /** Is `semver1` higher than `semver2`?*/ | ||
} | ||
function writeAutoImporterFile(fileContent) { | ||
(0, utils_js_1.assertPosixPath)(autoImporterFilePath); | ||
(0, utils_js_1.assert)((autoImporterFilePath.split('/dist/esm/').length === 2 && autoImporterFilePath.split('/dist/cjs/').length === 1) || | ||
(autoImporterFilePath.split('/dist/esm/').length === 1 && autoImporterFilePath.split('/dist/cjs/').length === 2)); | ||
function writeAutoImporterFile(getFileContent) { | ||
{ | ||
const { isCJS } = analyzeDistPath(autoImporterFilePath); | ||
(0, utils_js_1.assert)(isCJS === isCJSEnv); | ||
} | ||
const autoImporterFilePathEsm = autoImporterFilePath.replace('/dist/cjs/', '/dist/esm/'); | ||
const autoImporterFilePathCjs = autoImporterFilePath.replace('/dist/esm/', '/dist/cjs/'); | ||
[autoImporterFilePathEsm, autoImporterFilePathCjs].forEach((autoImporterFilePathResolved) => { | ||
(0, fs_1.writeFileSync)(autoImporterFilePathResolved, fileContent(autoImporterFilePathResolved)); | ||
const { exportStatement } = analyzeDistPath(autoImporterFilePathResolved); | ||
const fileContent = getFileContent(exportStatement, autoImporterFilePathResolved); | ||
(0, fs_1.writeFileSync)(autoImporterFilePathResolved, fileContent); | ||
}); | ||
} | ||
function analyzeDistPath(autoImporterFilePath) { | ||
(0, utils_js_1.assertPosixPath)(autoImporterFilePath); | ||
const isCJS = autoImporterFilePath.includes('/dist/cjs/'); | ||
const isESM = autoImporterFilePath.includes('/dist/esm/'); | ||
if (isCJS) | ||
(0, utils_js_1.assert)(autoImporterFilePath.split('/dist/cjs/').length === 2); | ||
if (isESM) | ||
(0, utils_js_1.assert)(autoImporterFilePath.split('/dist/esm/').length === 2); | ||
(0, utils_js_1.assert)(isCJS || isESM); | ||
(0, utils_js_1.assert)(!(isCJS && isESM)); | ||
const exportStatement = isCJS ? 'exports.' : 'export const '; | ||
return { isCJS, exportStatement }; | ||
} |
@@ -28,1 +28,2 @@ "use strict"; | ||
__exportStar(require("../utils/isNullish.js"), exports); | ||
__exportStar(require("../utils/deepEqual.js"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PROJECT_VERSION = void 0; | ||
exports.PROJECT_VERSION = '0.7.10'; | ||
exports.PROJECT_VERSION = '0.7.11-commit-3da168b'; |
export { serverProductionEntryPlugin }; | ||
export { serverEntryVirtualId }; | ||
import { isYarnPnP, assert, assertPosixPath, viteIsSSR, isAbsolutePath, toPosixPath, projectInfo, objectAssign, joinEnglish, findRollupBundleEntry, assertUsage, isNotNullish, injectRollupInputs, normalizeRollupInput, } from './utils.js'; | ||
import { isYarnPnP, assert, assertPosixPath, viteIsSSR, isAbsolutePath, toPosixPath, projectInfo, objectAssign, joinEnglish, findRollupBundleEntry, assertUsage, isNotNullish, injectRollupInputs, normalizeRollupInput, deepEqual, } from './utils.js'; | ||
import path from 'path'; | ||
@@ -16,4 +16,3 @@ import { writeFileSync } from 'fs'; | ||
const __dirname_ = toPosixPath(path.dirname(fileURLToPath(importMetaUrl))); | ||
const isCJS = 'import.meta.resolve' === 'require.resolve'; // see dist-cjs-fixup.js | ||
const exportStatement = isCJS ? 'exports.' : 'export const '; | ||
const isCJSEnv = 'import.meta.resolve' === 'require.resolve'; // see dist-cjs-fixup.js | ||
const require_ = createRequire(importMetaUrl); | ||
@@ -36,26 +35,62 @@ const autoImporterFilePath = toPosixPath(require_.resolve('../runtime/autoImporter.js')); | ||
let config; | ||
let library; | ||
let skip; | ||
const { libraryName } = pluginConfigProvidedByLibrary; | ||
assert(libraryName); | ||
let isClientBuild; | ||
let isNotLeaderInstance; | ||
let librariesLength; | ||
const skip = () => { | ||
assert('boolean' === typeof isNotLeaderInstance); | ||
assert('boolean' === typeof isClientBuild); | ||
return isNotLeaderInstance || isClientBuild; | ||
}; | ||
return [ | ||
{ | ||
name: pluginName, | ||
name: `${pluginName}:config:pre`, | ||
apply: 'build', | ||
// We must run the pre-hook configResolved() of *all* libraries before any post-hook configResolved() hook is called (otherwise isLeaderPluginInstance() will miss libraries and won't work) | ||
enforce: 'pre', | ||
configResolved: { | ||
order: 'pre', | ||
handler(configUnresolved) { | ||
config = resolveConfig(configUnresolved, libraryName, pluginConfigProvidedByLibrary); | ||
assert(config._vitePluginServerEntry.libraries.find((l) => l.libraryName === libraryName)); | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: `${pluginName}:config:post`, | ||
apply: 'build', | ||
// We need to run this plugin after other plugin instances, so that assertApiVersions() works also for libraries using older plugin versions | ||
enforce: 'post', | ||
configResolved() { | ||
if (skip) | ||
return; | ||
if (!isLeaderPluginInstance(config, library)) { | ||
skip = true; | ||
return; | ||
} | ||
assertApiVersions(config, pluginConfigProvidedByLibrary.libraryName); | ||
applyPluginConfigProvidedByUser(config); | ||
if (!config._vitePluginServerEntry.disableServerEntryEmit) { | ||
const serverEntryName = getServerEntryName(config); | ||
config.build.rollupOptions.input = injectRollupInputs({ [serverEntryName]: serverEntryVirtualId }, config); | ||
} | ||
configResolved: { | ||
order: 'post', | ||
handler() { | ||
assertUsage(typeof config.build.ssr !== 'string', "Setting the server build entry over the Vite configuration `build.ssr` (i.e. `--ssr path/to/entry.js`) isn't supported (because of a Vite bug), see workaround at https://github.com/brillout/vite-plugin-server-entry/issues/9#issuecomment-2027641624"); | ||
isClientBuild = !viteIsSSR(config); | ||
{ | ||
const prev = librariesLength; | ||
librariesLength = config._vitePluginServerEntry.libraries.length; | ||
assert([undefined, librariesLength].includes(prev)); | ||
} | ||
{ | ||
const prev = isNotLeaderInstance; | ||
isNotLeaderInstance = !isLeaderPluginInstance(config, libraryName); | ||
assert([undefined, isNotLeaderInstance].includes(prev)); | ||
} | ||
if (skip()) | ||
return; | ||
assertApiVersions(config, pluginConfigProvidedByLibrary.libraryName); | ||
applyPluginConfigProvidedByUser(config); | ||
if (!config._vitePluginServerEntry.disableServerEntryEmit) { | ||
const serverEntryName = getServerEntryName(config); | ||
config.build.rollupOptions.input = injectRollupInputs({ [serverEntryName]: serverEntryVirtualId }, config); | ||
} | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: `${pluginName}:hooks`, | ||
apply: 'build', | ||
buildStart() { | ||
if (skip) | ||
if (skip()) | ||
return; | ||
@@ -65,3 +100,3 @@ clearAutoImporter(config); | ||
resolveId(id) { | ||
if (skip) | ||
if (skip()) | ||
return; | ||
@@ -73,3 +108,3 @@ if (id === serverEntryVirtualId) { | ||
load(id) { | ||
if (skip) | ||
if (skip()) | ||
return; | ||
@@ -83,3 +118,3 @@ assert(id !== serverEntryVirtualId); | ||
generateBundle(_rollupOptions, bundle) { | ||
if (skip) | ||
if (skip()) | ||
return; | ||
@@ -101,24 +136,26 @@ // Write node_modules/@brillout/vite-plugin-server-entry/dist/autoImporter.js | ||
{ | ||
name: `${pluginName}:config`, | ||
apply: 'build', | ||
// We need to run this plugin before in order to make isLeaderPluginInstance() work | ||
enforce: 'pre', | ||
configResolved(configUnresolved) { | ||
// Upon the server-side build (`$ vite build --ssr`), we need to override the previous `skip` value set by the client-side build (`$ vite build`). | ||
skip = !viteIsSSR(configUnresolved); | ||
if (skip) | ||
return; | ||
assertUsage(typeof configUnresolved.build.ssr !== 'string', "Setting the server build entry over the Vite configuration `build.ssr` (i.e. `--ssr path/to/entry.js`) isn't supported (because of a Vite bug), see workaround at https://github.com/brillout/vite-plugin-server-entry/issues/9#issuecomment-2027641624"); | ||
const resolved = resolveConfig(configUnresolved, pluginConfigProvidedByLibrary); | ||
config = resolved.config; | ||
library = resolved.library; | ||
}, | ||
}, | ||
{ | ||
name: `${pluginName}:optimizeDeps`, | ||
config() { | ||
if (isCJSEnv) | ||
return; | ||
return { | ||
ssr: { | ||
optimizeDeps: { | ||
// Needed for @cloudflare/vite-plugin | ||
// Needed for @cloudflare/vite-plugin to avoid following error during SSR optimizeDeps scanning: | ||
// ```console | ||
// ✘ [ERROR] Could not resolve "../../../../../../../../../examples/react-full/dist/server/entry.mjs" | ||
// ../../node_modules/.pnpm/@brillout+vite-plugin-server-entry@0.7.9/node_modules/@brillout/vite-plugin-server-entry/dist/esm/runtime/autoImporter.js:3:58: | ||
// 3 │ export const loadServerEntry = async () => { await import("../../../../../../../../../examples/react-full/dist/server/entry.mjs"); }; | ||
// ╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
// | ||
// Error: Build failed with 1 error: | ||
// ../../node_modules/.pnpm/@brillout+vite-plugin-server-entry@0.7.9/node_modules/@brillout/vite-plugin-server-entry/dist/esm/runtime/autoImporter.js:3:58: ERROR: Could not resolve "../../../../../../../../../examples/react-full/dist/server/entry.mjs" | ||
// at failureErrorWithLog (/home/rom/code/vike/node_modules/.pnpm/esbuild@0.25.4/node_modules/esbuild/lib/main.js:1463:15) | ||
// at /home/rom/code/vike/node_modules/.pnpm/esbuild@0.25.4/node_modules/esbuild/lib/main.js:924:25 | ||
// at /home/rom/code/vike/node_modules/.pnpm/esbuild@0.25.4/node_modules/esbuild/lib/main.js:1341:9 | ||
// at processTicksAndRejections (node:internal/process/task_queues:105:5) { | ||
// errors: [Getter/Setter], | ||
// warnings: [Getter/Setter] | ||
// } | ||
// ``` | ||
exclude: ['@brillout/vite-plugin-server-entry'], | ||
@@ -132,4 +169,4 @@ }, | ||
} | ||
function resolveConfig(configUnresolved, pluginConfigProvidedByLibrary) { | ||
assert(viteIsSSR(configUnresolved)); | ||
function resolveConfig(configUnresolved, libraryName, pluginConfigProvidedByLibrary) { | ||
assert(pluginConfigProvidedByLibrary.libraryName === libraryName); | ||
const pluginConfigResolved = configUnresolved._vitePluginServerEntry ?? { | ||
@@ -142,14 +179,20 @@ libraries: [], | ||
}; | ||
const library = { | ||
objectAssign(configUnresolved, { | ||
_vitePluginServerEntry: pluginConfigResolved, | ||
}); | ||
const libraryNew = { | ||
getServerProductionEntry: pluginConfigProvidedByLibrary.getServerProductionEntry, | ||
libraryName: pluginConfigProvidedByLibrary.libraryName, | ||
libraryName, | ||
pluginVersion: projectInfo.projectVersion, | ||
apiVersion, | ||
}; | ||
pluginConfigResolved.libraries.push(library); | ||
objectAssign(configUnresolved, { | ||
_vitePluginServerEntry: pluginConfigResolved, | ||
}); | ||
const libraryFound = pluginConfigResolved.libraries.find((l) => l.libraryName === libraryName); | ||
if (!libraryFound) { | ||
pluginConfigResolved.libraries.push(libraryNew); | ||
} | ||
else { | ||
assert(deepEqual(libraryNew, libraryFound)); | ||
} | ||
const config = configUnresolved; | ||
return { config, library }; | ||
return config; | ||
} | ||
@@ -169,6 +212,7 @@ function applyPluginConfigProvidedByUser(config) { | ||
} | ||
function isLeaderPluginInstance(config, library) { | ||
function isLeaderPluginInstance(config, libraryName) { | ||
const { libraries } = config._vitePluginServerEntry; | ||
const pluginVersionCurrent = projectInfo.projectVersion; | ||
assert(libraries.includes(library)); | ||
const library = libraries.find((l) => l.libraryName === libraryName); | ||
assert(library); | ||
const isNotUsingNewestPluginVersion = libraries.some((lib) => { | ||
@@ -210,3 +254,3 @@ // Can be undefined when set by an older @brillout/vite-plugin-dist-importer version | ||
assert(!isYarnPnP()); | ||
writeAutoImporterFile((autoImporterFilePathResolved) => [ | ||
writeAutoImporterFile((exportStatement, autoImporterFilePathResolved) => [ | ||
`${exportStatement}status = 'SET';`, | ||
@@ -226,8 +270,6 @@ `${exportStatement}pluginVersion = ${JSON.stringify(projectInfo.projectVersion)};`, | ||
function clearAutoImporter(config) { | ||
if (isAutoImportDisabled(config)) { | ||
if (isYarnPnP()) | ||
return; | ||
} | ||
assert(!isYarnPnP()); | ||
const status = 'BUILDING'; | ||
writeAutoImporterFile(() => [`${exportStatement}status = '${status}';`, ''].join('\n')); | ||
const status = isAutoImportDisabled(config) ? 'DISABLED' : 'BUILDING'; | ||
writeAutoImporterFile((exportStatement) => [`${exportStatement}status = '${status}';`, ''].join('\n')); | ||
} | ||
@@ -353,11 +395,27 @@ /** Is `semver1` higher than `semver2`?*/ | ||
} | ||
function writeAutoImporterFile(fileContent) { | ||
assertPosixPath(autoImporterFilePath); | ||
assert((autoImporterFilePath.split('/dist/esm/').length === 2 && autoImporterFilePath.split('/dist/cjs/').length === 1) || | ||
(autoImporterFilePath.split('/dist/esm/').length === 1 && autoImporterFilePath.split('/dist/cjs/').length === 2)); | ||
function writeAutoImporterFile(getFileContent) { | ||
{ | ||
const { isCJS } = analyzeDistPath(autoImporterFilePath); | ||
assert(isCJS === isCJSEnv); | ||
} | ||
const autoImporterFilePathEsm = autoImporterFilePath.replace('/dist/cjs/', '/dist/esm/'); | ||
const autoImporterFilePathCjs = autoImporterFilePath.replace('/dist/esm/', '/dist/cjs/'); | ||
[autoImporterFilePathEsm, autoImporterFilePathCjs].forEach((autoImporterFilePathResolved) => { | ||
writeFileSync(autoImporterFilePathResolved, fileContent(autoImporterFilePathResolved)); | ||
const { exportStatement } = analyzeDistPath(autoImporterFilePathResolved); | ||
const fileContent = getFileContent(exportStatement, autoImporterFilePathResolved); | ||
writeFileSync(autoImporterFilePathResolved, fileContent); | ||
}); | ||
} | ||
function analyzeDistPath(autoImporterFilePath) { | ||
assertPosixPath(autoImporterFilePath); | ||
const isCJS = autoImporterFilePath.includes('/dist/cjs/'); | ||
const isESM = autoImporterFilePath.includes('/dist/esm/'); | ||
if (isCJS) | ||
assert(autoImporterFilePath.split('/dist/cjs/').length === 2); | ||
if (isESM) | ||
assert(autoImporterFilePath.split('/dist/esm/').length === 2); | ||
assert(isCJS || isESM); | ||
assert(!(isCJS && isESM)); | ||
const exportStatement = isCJS ? 'exports.' : 'export const '; | ||
return { isCJS, exportStatement }; | ||
} |
@@ -12,1 +12,2 @@ export * from '../utils/assert.js'; | ||
export * from '../utils/isNullish.js'; | ||
export * from '../utils/deepEqual.js'; |
@@ -12,1 +12,2 @@ export * from '../utils/assert.js'; | ||
export * from '../utils/isNullish.js'; | ||
export * from '../utils/deepEqual.js'; |
export { assert }; | ||
export { assertUsage }; | ||
export { logLabel }; | ||
declare const logLabel: "[@brillout/vite-plugin-server-entry@0.7.10]"; | ||
declare const logLabel: "[@brillout/vite-plugin-server-entry@0.7.11-commit-3da168b]"; | ||
declare function assert(condition: unknown, debugInfo?: unknown): asserts condition; | ||
declare function assertUsage(condition: unknown, errorMessage: string): asserts condition; |
@@ -1,1 +0,1 @@ | ||
export declare const PROJECT_VERSION: "0.7.10"; | ||
export declare const PROJECT_VERSION: "0.7.11-commit-3da168b"; |
@@ -1,1 +0,1 @@ | ||
export const PROJECT_VERSION = '0.7.10'; | ||
export const PROJECT_VERSION = '0.7.11-commit-3da168b'; |
export declare const projectInfo: { | ||
projectName: "@brillout/vite-plugin-server-entry"; | ||
npmPackageName: "@brillout/vite-plugin-server-entry"; | ||
projectVersion: "0.7.10"; | ||
projectVersion: "0.7.11-commit-3da168b"; | ||
githubRepository: "https://github.com/brillout/vite-plugin-server-entry"; | ||
}; |
{ | ||
"name": "@brillout/vite-plugin-server-entry", | ||
"version": "0.7.10", | ||
"version": "0.7.11-commit-3da168b", | ||
"repository": "https://github.com/brillout/vite-plugin-server-entry", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
116276
7.9%96
3.23%2391
6.08%