diff --git a/packages/docs/src/repl/bundled.tsx b/packages/docs/src/repl/bundled.tsx index 6ce706ac5f1..b9f30fb6d8f 100644 --- a/packages/docs/src/repl/bundled.tsx +++ b/packages/docs/src/repl/bundled.tsx @@ -9,10 +9,10 @@ import terserPkgJson from 'terser/package.json'; import terserJs from '../../node_modules/terser/dist/bundle.min.js?raw-source'; import qBuild from '../../node_modules/@builder.io/qwik/dist/build/index.d.ts?raw-source'; -import qCoreCjs from '../../node_modules/@builder.io/qwik/dist/core.cjs?raw-source'; +import qCoreCjs from '../../node_modules/@builder.io/qwik/dist/core.qwik.cjs?raw-source'; import qCoreDts from '../../node_modules/@builder.io/qwik/dist/core.d.ts?raw-source'; -import qCoreMinMjs from '../../node_modules/@builder.io/qwik/dist/core.min.mjs?raw-source'; -import qCoreMjs from '../../node_modules/@builder.io/qwik/dist/core.mjs?raw-source'; +import qCoreMinMjs from '../../node_modules/@builder.io/qwik/dist/core.min.qwik.mjs?raw-source'; +import qCoreMjs from '../../node_modules/@builder.io/qwik/dist/core.qwik.mjs?raw-source'; import qOptimizerCjs from '../../node_modules/@builder.io/qwik/dist/optimizer.cjs?raw-source'; import qServerCjs from '../../node_modules/@builder.io/qwik/dist/server.cjs?raw-source'; import qServerDts from '../../node_modules/@builder.io/qwik/dist/server.d.ts?raw-source'; @@ -48,10 +48,10 @@ export const bundled: PkgUrls = { [QWIK_PKG_NAME]: { version: qwikVersion, '/dist/build/index.d.ts': qBuild, - '/dist/core.cjs': qCoreCjs, + '/dist/core.qwik.cjs': qCoreCjs, '/dist/core.d.ts': qCoreDts, - '/dist/core.min.mjs': qCoreMinMjs, - '/dist/core.mjs': qCoreMjs, + '/dist/core.min.qwik.mjs': qCoreMinMjs, + '/dist/core.qwik.mjs': qCoreMjs, '/dist/optimizer.cjs': qOptimizerCjs, '/dist/server.cjs': qServerCjs, '/dist/server.d.ts': qServerDts, diff --git a/packages/docs/src/repl/repl.tsx b/packages/docs/src/repl/repl.tsx index b68ad72f894..78c6076ac76 100644 --- a/packages/docs/src/repl/repl.tsx +++ b/packages/docs/src/repl/repl.tsx @@ -170,13 +170,14 @@ const getDependencies = (input: ReplAppInput) => { if (input.version !== 'bundled') { const [M, m, p] = input.version.split('-')[0].split('.').map(Number); const prefix = M > 1 || (M == 1 && (m > 7 || (m == 7 && p >= 2))) ? '/dist/' : '/'; + const qwik = M > 1 || (M == 1 && m >= 9) ? '.qwik' : ''; out[QWIK_PKG_NAME] = { version: input.version, }; for (const p of [ - `${prefix}core.cjs`, - `${prefix}core.mjs`, - `${prefix}core.min.mjs`, + `${prefix}core${qwik}.cjs`, + `${prefix}core${qwik}.mjs`, + `${prefix}core.min${qwik}.mjs`, `${prefix}optimizer.cjs`, `${prefix}server.cjs`, `/bindings/qwik.wasm.cjs`, diff --git a/packages/docs/src/repl/worker/repl-dependencies.ts b/packages/docs/src/repl/worker/repl-dependencies.ts index 63a00210de0..f64860a1479 100644 --- a/packages/docs/src/repl/worker/repl-dependencies.ts +++ b/packages/docs/src/repl/worker/repl-dependencies.ts @@ -13,6 +13,9 @@ export const depResponse = async (pkgName: string, pkgPath: string) => { if (M > 1 || (M == 1 && (m > 7 || (m == 7 && p >= 2)))) { pkgPath = `/dist${pkgPath}`; } + if (!(M > 2 || (M === 1 && (m > 8 || (m === 8 && version.includes('-dev')))))) { + pkgPath = pkgPath.replace('.qwik', ''); + } } const url = options.deps[pkgName][pkgPath]; if (!url) { @@ -71,7 +74,7 @@ const _loadDependencies = async (replOptions: ReplInputOptions) => { } if (!isSameQwikVersion(self.qwikCore?.version)) { - await exec(QWIK_PKG_NAME, '/core.cjs'); + await exec(QWIK_PKG_NAME, '/core.qwik.cjs'); if (self.qwikCore) { console.debug(`Loaded @builder.io/qwik: ${self.qwikCore.version}`); } else { diff --git a/packages/docs/src/repl/worker/repl-plugins.ts b/packages/docs/src/repl/worker/repl-plugins.ts index 2e9cd574f9a..d57a1d499a7 100644 --- a/packages/docs/src/repl/worker/repl-plugins.ts +++ b/packages/docs/src/repl/worker/repl-plugins.ts @@ -63,7 +63,7 @@ export const replResolver = (options: ReplInputOptions, buildMode: 'client' | 's } } - const rsp = await depResponse('@builder.io/qwik', '/core.mjs'); + const rsp = await depResponse('@builder.io/qwik', '/core.qwik.mjs'); if (rsp) { return rsp.text(); } diff --git a/packages/qwik/package.json b/packages/qwik/package.json index b0497f66227..76e9a329b5e 100644 --- a/packages/qwik/package.json +++ b/packages/qwik/package.json @@ -42,15 +42,15 @@ ".": { "types": "./dist/core.d.ts", "import": { - "development": "./dist/core.mjs", - "production": "./dist/core.prod.mjs", - "default": "./dist/core.prod.mjs", - "min": "./dist/core.min.mjs" + "development": "./dist/core.qwik.mjs", + "production": "./dist/core.prod.qwik.mjs", + "default": "./dist/core.prod.qwik.mjs", + "min": "./dist/core.min.qwik.mjs" }, "require": { - "development": "./dist/core.cjs", - "production": "./dist/core.prod.cjs", - "default": "./dist/core.prod.cjs" + "development": "./dist/core.qwik.cjs", + "production": "./dist/core.prod.qwik.cjs", + "default": "./dist/core.prod.qwik.cjs" } }, "./cli": { @@ -59,29 +59,29 @@ "./jsx-runtime": { "types": "./dist/jsx-runtime.d.ts", "import": { - "development": "./dist/core.mjs", - "production": "./dist/core.prod.mjs", - "default": "./dist/core.prod.mjs", - "min": "./dist/core.min.mjs" + "development": "./dist/core.qwik.mjs", + "production": "./dist/core.prod.qwik.mjs", + "default": "./dist/core.prod.qwik.mjs", + "min": "./dist/core.min.qwik.mjs" }, "require": { - "development": "./dist/core.cjs", - "production": "./dist/core.prod.cjs", - "default": "./dist/core.prod.cjs" + "development": "./dist/core.qwik.cjs", + "production": "./dist/core.prod.qwik.cjs", + "default": "./dist/core.prod.qwik.cjs" } }, "./jsx-dev-runtime": { "types": "./dist/jsx-runtime.d.ts", "import": { - "development": "./dist/core.mjs", - "production": "./dist/core.prod.mjs", - "default": "./dist/core.mjs", - "min": "./dist/core.min.mjs" + "development": "./dist/core.qwik.mjs", + "production": "./dist/core.prod.qwik.mjs", + "default": "./dist/core.qwik.mjs", + "min": "./dist/core.min.qwik.mjs" }, "require": { - "development": "./dist/core.cjs", - "production": "./dist/core.prod.cjs", - "default": "./dist/core.cjs" + "development": "./dist/core.qwik.cjs", + "production": "./dist/core.prod.qwik.cjs", + "default": "./dist/core.qwik.cjs" } }, "./build": { diff --git a/scripts/build.ts b/scripts/build.ts index af9e2fb1c07..55bed44a4ac 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -169,16 +169,16 @@ export async function build(config: BuildConfig) { [join(config.srcQwikDir, 'core')]: async () => { await submoduleCore({ ...config, dev: true }); await copyFile( - join(config.srcQwikDir, '..', 'dist', 'core.cjs'), - join(config.srcQwikDir, '..', 'dist', 'core.prod.cjs') + join(config.srcQwikDir, '..', 'dist', 'core.qwik.cjs'), + join(config.srcQwikDir, '..', 'dist', 'core.prod.qwik.cjs') ); await copyFile( - join(config.srcQwikDir, '..', 'dist', 'core.mjs'), - join(config.srcQwikDir, '..', 'dist', 'core.prod.mjs') + join(config.srcQwikDir, '..', 'dist', 'core.qwik.mjs'), + join(config.srcQwikDir, '..', 'dist', 'core.prod.qwik.mjs') ); console.log( - join(config.srcQwikDir, '..', 'dist', 'core.cjs'), - join(config.srcQwikDir, '..', 'dist', 'core.prod.cjs') + join(config.srcQwikDir, '..', 'dist', 'core.qwik.cjs'), + join(config.srcQwikDir, '..', 'dist', 'core.prod.qwik.cjs') ); }, [join(config.srcQwikDir, 'optimizer')]: () => submoduleOptimizer(config), diff --git a/scripts/submodule-core.ts b/scripts/submodule-core.ts index 779ad822404..a869115b666 100644 --- a/scripts/submodule-core.ts +++ b/scripts/submodule-core.ts @@ -44,7 +44,7 @@ async function submoduleCoreProd(config: BuildConfig) { const esmOutput: OutputOptions = { dir: join(config.distQwikPkgDir), format: 'es', - entryFileNames: 'core.mjs', + entryFileNames: 'core.qwik.mjs', sourcemap: true, banner: getBanner('@builder.io/qwik', config.distVersion), }; @@ -53,7 +53,7 @@ async function submoduleCoreProd(config: BuildConfig) { dir: join(config.distQwikPkgDir), format: 'umd', name: 'qwikCore', - entryFileNames: 'core.cjs', + entryFileNames: 'core.qwik.cjs', sourcemap: true, globals: { '@builder.io/qwik/build': 'qwikBuild', @@ -65,9 +65,9 @@ async function submoduleCoreProd(config: BuildConfig) { await Promise.all([build.write(esmOutput), build.write(cjsOutput)]); - console.log('🦊 core.mjs:', await fileSize(join(config.distQwikPkgDir, 'core.mjs'))); + console.log('🦊 core.qwik.mjs:', await fileSize(join(config.distQwikPkgDir, 'core.qwik.mjs'))); - const inputCore = join(config.distQwikPkgDir, 'core.mjs'); + const inputCore = join(config.distQwikPkgDir, 'core.qwik.mjs'); const inputMin: InputOptions = { input: inputCore, onwarn: rollupOnWarn, @@ -98,7 +98,7 @@ async function submoduleCoreProd(config: BuildConfig) { await buildMin.write({ dir: join(config.distQwikPkgDir), format: 'es', - entryFileNames: 'core.min.mjs', + entryFileNames: 'core.min.qwik.mjs', plugins: [ { name: 'minify', @@ -147,7 +147,7 @@ async function submoduleCoreProd(config: BuildConfig) { const indx = Math.max(selfIdx); if (indx !== -1) { throw new Error( - `"core.min.mjs" should not have any global references, and should have been removed for a production minified build\n` + + `"core.min.qwik.mjs" should not have any global references, and should have been removed for a production minified build\n` + esmCleanCode.substring(indx, indx + 10) + '\n' + esmCleanCode.substring(indx - 100, indx + 300) @@ -161,16 +161,19 @@ async function submoduleCoreProd(config: BuildConfig) { ], }); - console.log('🐭 core.min.mjs:', await fileSize(join(config.distQwikPkgDir, 'core.min.mjs'))); + console.log( + '🐭 core.min.qwik.mjs:', + await fileSize(join(config.distQwikPkgDir, 'core.min.qwik.mjs')) + ); - let esmCode = await readFile(join(config.distQwikPkgDir, 'core.mjs'), 'utf-8'); - let cjsCode = await readFile(join(config.distQwikPkgDir, 'core.cjs'), 'utf-8'); + let esmCode = await readFile(join(config.distQwikPkgDir, 'core.qwik.mjs'), 'utf-8'); + let cjsCode = await readFile(join(config.distQwikPkgDir, 'core.qwik.cjs'), 'utf-8'); // fixup the Vite base url cjsCode = cjsCode.replaceAll('undefined.BASE_URL', 'globalThis.BASE_URL||"/"'); - await writeFile(join(config.distQwikPkgDir, 'core.cjs'), cjsCode); + await writeFile(join(config.distQwikPkgDir, 'core.qwik.cjs'), cjsCode); - await submoduleCoreProduction(config, esmCode, join(config.distQwikPkgDir, 'core.prod.mjs')); - await submoduleCoreProduction(config, cjsCode, join(config.distQwikPkgDir, 'core.prod.cjs')); + await submoduleCoreProduction(config, esmCode, join(config.distQwikPkgDir, 'core.prod.qwik.mjs')); + await submoduleCoreProduction(config, cjsCode, join(config.distQwikPkgDir, 'core.prod.qwik.cjs')); } async function submoduleCoreProduction(config: BuildConfig, code: string, outPath: string) { @@ -225,7 +228,7 @@ async function submoduleCoreDev(config: BuildConfig) { ...opts, external: ['@builder.io/qwik/build'], format: 'esm', - outExtension: { '.js': '.mjs' }, + outExtension: { '.js': '.qwik.mjs' }, }); const cjs = build({ @@ -237,7 +240,7 @@ async function submoduleCoreDev(config: BuildConfig) { 'import.meta.env.BASE_URL': '"globalThis.BASE_URL||\'/\'"', }, format: 'cjs', - outExtension: { '.js': '.cjs' }, + outExtension: { '.js': '.qwik.cjs' }, banner: { js: `globalThis.qwikCore = (function (module) {`, }, @@ -249,15 +252,21 @@ async function submoduleCoreDev(config: BuildConfig) { await Promise.all([esm, cjs]); // Point the minified and prod versions to the dev versions - await writeFile(join(config.distQwikPkgDir, 'core.prod.mjs'), `export * from './core.mjs';\n`); await writeFile( - join(config.distQwikPkgDir, 'core.prod.cjs'), - `module.exports = require('./core.cjs');\n` + join(config.distQwikPkgDir, 'core.prod.qwik.mjs'), + `export * from './core.qwik.mjs';\n` + ); + await writeFile( + join(config.distQwikPkgDir, 'core.prod.qwik.cjs'), + `module.exports = require('./core.qwik.cjs');\n` + ); + await writeFile( + join(config.distQwikPkgDir, 'core.min.qwik.mjs'), + `export * from './core.qwik.mjs';\n` ); - await writeFile(join(config.distQwikPkgDir, 'core.min.mjs'), `export * from './core.mjs';\n`); await writeFile( - join(config.distQwikPkgDir, 'core.min.cjs'), - `module.exports = require('./core.cjs');\n` + join(config.distQwikPkgDir, 'core.min.qwik.cjs'), + `module.exports = require('./core.qwik.cjs');\n` ); console.log('🐬', submodule, '(dev)'); diff --git a/scripts/submodule-server.ts b/scripts/submodule-server.ts index e0b1828822f..97a8e0721d8 100644 --- a/scripts/submodule-server.ts +++ b/scripts/submodule-server.ts @@ -115,9 +115,9 @@ async function getQwikDomVersion(config: BuildConfig) { const browserCjsRequireShim = ` if (typeof require !== 'function' && typeof location !== 'undefined' && typeof navigator !== 'undefined') { - // shim cjs require() for core.cjs within a browser + // shim cjs require() for core.qwik.cjs within a browser globalThis.require = function(path) { - if (path === './core.cjs' || path === '@builder.io/qwik') { + if (path === './core.qwik.cjs' || path === '@builder.io/qwik') { if (!self.qwikCore) { throw new Error('Qwik Core global, "globalThis.qwikCore", must already be loaded for the Qwik Server to be used within a browser.'); } diff --git a/scripts/submodule-testing.ts b/scripts/submodule-testing.ts index b8620dbea9b..28e411ef100 100644 --- a/scripts/submodule-testing.ts +++ b/scripts/submodule-testing.ts @@ -25,7 +25,7 @@ export async function submoduleTesting(config: BuildConfig) { banner: { js: getBanner('@builder.io/qwik/testing', config.distVersion) }, outExtension: { '.js': '.mjs' }, plugins: [ - importPath(/^@builder\.io\/qwik$/, '../core.mjs'), + importPath(/^@builder\.io\/qwik$/, '../core.qwik.mjs'), importPath(/^@builder\.io\/qwik\/optimizer$/, '../optimizer.mjs'), importPath(/^@builder\.io\/qwik\/server$/, '../server.mjs'), ], @@ -44,7 +44,7 @@ export async function submoduleTesting(config: BuildConfig) { js: getBanner('@builder.io/qwik/testing', config.distVersion), }, plugins: [ - importPath(/^@builder\.io\/qwik$/, '../core.cjs'), + importPath(/^@builder\.io\/qwik$/, '../core.qwik.cjs'), importPath(/^@builder\.io\/qwik\/optimizer$/, '../optimizer.cjs'), importPath(/^@builder\.io\/qwik\/server$/, '../server.cjs'), ], diff --git a/scripts/validate-build.ts b/scripts/validate-build.ts index 3e6943ae364..a1754094006 100644 --- a/scripts/validate-build.ts +++ b/scripts/validate-build.ts @@ -96,9 +96,9 @@ export async function validateBuild(config: BuildConfig) { await validatePackageJson(config, pkg, errors); await Promise.all([ - validateModuleTreeshake(config, join(config.distQwikPkgDir, 'core.min.mjs')), - validateModuleTreeshake(config, join(config.distQwikPkgDir, 'core.prod.mjs')), - validateModuleTreeshake(config, join(config.distQwikPkgDir, 'core.mjs')), + validateModuleTreeshake(config, join(config.distQwikPkgDir, 'core.min.qwik.mjs')), + validateModuleTreeshake(config, join(config.distQwikPkgDir, 'core.prod.qwik.mjs')), + validateModuleTreeshake(config, join(config.distQwikPkgDir, 'core.qwik.mjs')), validateModuleTreeshake(config, join(config.distQwikPkgDir, 'server.mjs')), ]); if (config.qwikcity) {