@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); | ||
@@ -75,3 +74,3 @@ const autoImporterFilePath = (0, utils_js_1.toPosixPath)(require_.resolve('../runtime/autoImporter.js')); | ||
(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); | ||
isClientBuild = !(0, utils_js_1.isViteServerSide)(config, undefined); | ||
{ | ||
@@ -118,3 +117,3 @@ const prev = librariesLength; | ||
if (id === virtualIdPrefix + serverEntryVirtualId) { | ||
const serverProductionEntry = getServerProductionEntryAll(config); | ||
const serverProductionEntry = getServerProductionEntryAll(config, this.environment); | ||
return serverProductionEntry; | ||
@@ -133,3 +132,3 @@ } | ||
(0, utils_js_1.assert)(false, { entry }); | ||
setAutoImporter(config, entryFileName); | ||
setAutoImporter(config, this.environment, entryFileName); | ||
} | ||
@@ -144,2 +143,6 @@ else { | ||
config() { | ||
//* Not sure if we really need this. | ||
if (isCJSEnv) | ||
return; | ||
//*/ | ||
return { | ||
@@ -230,4 +233,4 @@ ssr: { | ||
} | ||
function getServerProductionEntryAll(config) { | ||
(0, utils_js_1.assert)((0, utils_js_1.viteIsSSR)(config)); | ||
function getServerProductionEntryAll(config, viteEnv) { | ||
(0, utils_js_1.assert)((0, utils_js_1.isViteServerSide)(config, viteEnv)); | ||
const serverProductionEntry = [ | ||
@@ -248,4 +251,4 @@ '// Generated by https://github.com/brillout/vite-plugin-server-entry', | ||
} | ||
function setAutoImporter(config, entryFileName) { | ||
const { distServerPathRelative, distServerPathAbsolute } = getDistServerPathRelative(config); | ||
function setAutoImporter(config, viteEnv, entryFileName) { | ||
const { distServerPathRelative, distServerPathAbsolute } = getDistServerPathRelative(config, viteEnv); | ||
const serverEntryFilePathRelative = path_1.default.posix.join(distServerPathRelative, entryFileName); | ||
@@ -257,3 +260,3 @@ const serverEntryFilePathAbsolute = path_1.default.posix.join(distServerPathAbsolute, entryFileName); | ||
(0, utils_js_1.assert)(!(0, utils_js_1.isYarnPnP)()); | ||
writeAutoImporterFile((autoImporterFilePathResolved) => [ | ||
writeAutoImporterFile(({ autoImporterFilePathResolved, exportStatement, isCJS }) => [ | ||
`${exportStatement}status = 'SET';`, | ||
@@ -264,6 +267,6 @@ `${exportStatement}pluginVersion = ${JSON.stringify(utils_js_1.projectInfo.projectVersion)};`, | ||
` autoImporterFilePathOriginal: ${JSON.stringify(autoImporterFilePathResolved)},`, | ||
' autoImporterFilePathActual: (() => { try { return `file://${__filename}` } catch { return null } })(),', | ||
` autoImporterFilePathActual: (() => { try { return ${isCJS ? '__filename' : '`file://${__filename}`'} } catch { return null } })(),`, | ||
` serverEntryFilePathRelative: ${JSON.stringify(serverEntryFilePathRelative)},`, | ||
` serverEntryFilePathOriginal: ${JSON.stringify(serverEntryFilePathAbsolute)},`, | ||
` serverEntryFilePathResolved: () => require.resolve(${JSON.stringify(serverEntryFilePathRelative)}),`, | ||
` serverEntryFilePathResolved: () => ${isCJS ? 'require' : 'import.meta'}.resolve(${JSON.stringify(serverEntryFilePathRelative)}),`, | ||
'};', | ||
@@ -277,3 +280,3 @@ '', | ||
const status = isAutoImportDisabled(config) ? 'DISABLED' : 'BUILDING'; | ||
writeAutoImporterFile(() => [`${exportStatement}status = '${status}';`, ''].join('\n')); | ||
writeAutoImporterFile(({ exportStatement }) => [`${exportStatement}status = '${status}';`, ''].join('\n')); | ||
} | ||
@@ -306,4 +309,4 @@ /** Is `semver1` higher than `semver2`?*/ | ||
} | ||
function getDistServerPathRelative(config) { | ||
(0, utils_js_1.assert)((0, utils_js_1.viteIsSSR)(config)); | ||
function getDistServerPathRelative(config, viteEnv) { | ||
(0, utils_js_1.assert)((0, utils_js_1.isViteServerSide)(config, viteEnv)); | ||
const { root } = config; | ||
@@ -400,11 +403,27 @@ const importerDir = __dirname_; | ||
} | ||
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, isCJS } = analyzeDistPath(autoImporterFilePathResolved); | ||
const fileContent = getFileContent({ autoImporterFilePathResolved, exportStatement, isCJS }); | ||
(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 }; | ||
} |
@@ -20,3 +20,3 @@ "use strict"; | ||
__exportStar(require("../utils/isYarnPnP.js"), exports); | ||
__exportStar(require("../utils/viteIsSSR.js"), exports); | ||
__exportStar(require("../utils/isViteServerSide.js"), exports); | ||
__exportStar(require("../utils/isAbsolutePath.js"), exports); | ||
@@ -23,0 +23,0 @@ __exportStar(require("../utils/projectInfo.js"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PROJECT_VERSION = void 0; | ||
exports.PROJECT_VERSION = '0.7.11'; | ||
exports.PROJECT_VERSION = '0.7.12-commit-d232fb4'; |
export { serverProductionEntryPlugin }; | ||
export { serverEntryVirtualId }; | ||
import { isYarnPnP, assert, assertPosixPath, viteIsSSR, isAbsolutePath, toPosixPath, projectInfo, objectAssign, joinEnglish, findRollupBundleEntry, assertUsage, isNotNullish, injectRollupInputs, normalizeRollupInput, deepEqual, } from './utils.js'; | ||
import { isYarnPnP, assert, assertPosixPath, isViteServerSide, 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); | ||
@@ -69,3 +68,3 @@ const autoImporterFilePath = toPosixPath(require_.resolve('../runtime/autoImporter.js')); | ||
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); | ||
isClientBuild = !isViteServerSide(config, undefined); | ||
{ | ||
@@ -112,3 +111,3 @@ const prev = librariesLength; | ||
if (id === virtualIdPrefix + serverEntryVirtualId) { | ||
const serverProductionEntry = getServerProductionEntryAll(config); | ||
const serverProductionEntry = getServerProductionEntryAll(config, this.environment); | ||
return serverProductionEntry; | ||
@@ -127,3 +126,3 @@ } | ||
assert(false, { entry }); | ||
setAutoImporter(config, entryFileName); | ||
setAutoImporter(config, this.environment, entryFileName); | ||
} | ||
@@ -138,2 +137,6 @@ else { | ||
config() { | ||
//* Not sure if we really need this. | ||
if (isCJSEnv) | ||
return; | ||
//*/ | ||
return { | ||
@@ -224,4 +227,4 @@ ssr: { | ||
} | ||
function getServerProductionEntryAll(config) { | ||
assert(viteIsSSR(config)); | ||
function getServerProductionEntryAll(config, viteEnv) { | ||
assert(isViteServerSide(config, viteEnv)); | ||
const serverProductionEntry = [ | ||
@@ -242,4 +245,4 @@ '// Generated by https://github.com/brillout/vite-plugin-server-entry', | ||
} | ||
function setAutoImporter(config, entryFileName) { | ||
const { distServerPathRelative, distServerPathAbsolute } = getDistServerPathRelative(config); | ||
function setAutoImporter(config, viteEnv, entryFileName) { | ||
const { distServerPathRelative, distServerPathAbsolute } = getDistServerPathRelative(config, viteEnv); | ||
const serverEntryFilePathRelative = path.posix.join(distServerPathRelative, entryFileName); | ||
@@ -251,3 +254,3 @@ const serverEntryFilePathAbsolute = path.posix.join(distServerPathAbsolute, entryFileName); | ||
assert(!isYarnPnP()); | ||
writeAutoImporterFile((autoImporterFilePathResolved) => [ | ||
writeAutoImporterFile(({ autoImporterFilePathResolved, exportStatement, isCJS }) => [ | ||
`${exportStatement}status = 'SET';`, | ||
@@ -258,6 +261,6 @@ `${exportStatement}pluginVersion = ${JSON.stringify(projectInfo.projectVersion)};`, | ||
` autoImporterFilePathOriginal: ${JSON.stringify(autoImporterFilePathResolved)},`, | ||
' autoImporterFilePathActual: (() => { try { return import.meta.url } catch { return null } })(),', | ||
` autoImporterFilePathActual: (() => { try { return ${isCJS ? '__filename' : 'import.meta.url'} } catch { return null } })(),`, | ||
` serverEntryFilePathRelative: ${JSON.stringify(serverEntryFilePathRelative)},`, | ||
` serverEntryFilePathOriginal: ${JSON.stringify(serverEntryFilePathAbsolute)},`, | ||
` serverEntryFilePathResolved: () => import.meta.resolve(${JSON.stringify(serverEntryFilePathRelative)}),`, | ||
` serverEntryFilePathResolved: () => ${isCJS ? 'require' : 'import.meta'}.resolve(${JSON.stringify(serverEntryFilePathRelative)}),`, | ||
'};', | ||
@@ -271,3 +274,3 @@ '', | ||
const status = isAutoImportDisabled(config) ? 'DISABLED' : 'BUILDING'; | ||
writeAutoImporterFile(() => [`${exportStatement}status = '${status}';`, ''].join('\n')); | ||
writeAutoImporterFile(({ exportStatement }) => [`${exportStatement}status = '${status}';`, ''].join('\n')); | ||
} | ||
@@ -300,4 +303,4 @@ /** Is `semver1` higher than `semver2`?*/ | ||
} | ||
function getDistServerPathRelative(config) { | ||
assert(viteIsSSR(config)); | ||
function getDistServerPathRelative(config, viteEnv) { | ||
assert(isViteServerSide(config, viteEnv)); | ||
const { root } = config; | ||
@@ -394,11 +397,27 @@ const importerDir = __dirname_; | ||
} | ||
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, isCJS } = analyzeDistPath(autoImporterFilePathResolved); | ||
const fileContent = getFileContent({ autoImporterFilePathResolved, exportStatement, isCJS }); | ||
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 }; | ||
} |
export * from '../utils/assert.js'; | ||
export * from '../utils/filesystemPathHandling.js'; | ||
export * from '../utils/isYarnPnP.js'; | ||
export * from '../utils/viteIsSSR.js'; | ||
export * from '../utils/isViteServerSide.js'; | ||
export * from '../utils/isAbsolutePath.js'; | ||
@@ -6,0 +6,0 @@ export * from '../utils/projectInfo.js'; |
export * from '../utils/assert.js'; | ||
export * from '../utils/filesystemPathHandling.js'; | ||
export * from '../utils/isYarnPnP.js'; | ||
export * from '../utils/viteIsSSR.js'; | ||
export * from '../utils/isViteServerSide.js'; | ||
export * from '../utils/isAbsolutePath.js'; | ||
@@ -6,0 +6,0 @@ export * from '../utils/projectInfo.js'; |
export { assert }; | ||
export { assertUsage }; | ||
export { logLabel }; | ||
declare const logLabel: "[@brillout/vite-plugin-server-entry@0.7.11]"; | ||
declare const logLabel: "[@brillout/vite-plugin-server-entry@0.7.12-commit-d232fb4]"; | ||
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.11"; | ||
export declare const PROJECT_VERSION: "0.7.12-commit-d232fb4"; |
@@ -1,1 +0,1 @@ | ||
export const PROJECT_VERSION = '0.7.11'; | ||
export const PROJECT_VERSION = '0.7.12-commit-d232fb4'; |
export declare const projectInfo: { | ||
projectName: "@brillout/vite-plugin-server-entry"; | ||
npmPackageName: "@brillout/vite-plugin-server-entry"; | ||
projectVersion: "0.7.11"; | ||
projectVersion: "0.7.12-commit-d232fb4"; | ||
githubRepository: "https://github.com/brillout/vite-plugin-server-entry"; | ||
}; |
{ | ||
"name": "@brillout/vite-plugin-server-entry", | ||
"version": "0.7.11", | ||
"version": "0.7.12-commit-d232fb4", | ||
"repository": "https://github.com/brillout/vite-plugin-server-entry", | ||
@@ -47,3 +47,3 @@ "dependencies": { | ||
"typescript": "^5.7.3", | ||
"vite": "^4.5.1" | ||
"vite": "^7.1.3" | ||
}, | ||
@@ -50,0 +50,0 @@ "typesVersions": { |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
117413
2.09%2406
2.08%