chore: compiler subpackage (#10988)

* move compiler.cjs to compiler/index.js

* changeset

* prettier

* ugh
pull/11023/head
Rich Harris 9 months ago committed by GitHub
parent 1c75b9ac4d
commit 4f3fae7c6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
breaking: move compiler.cjs to compiler/index.js

@ -11,6 +11,7 @@
**/vite.config.js **/vite.config.js
**/vite.prod.config.js **/vite.prod.config.js
**/node_modules **/node_modules
**/compiler/index.js
**/tests/** **/tests/**
@ -20,4 +21,4 @@ documentation/**
# contains a fork of the REPL which doesn't adhere to eslint rules # contains a fork of the REPL which doesn't adhere to eslint rules
sites/svelte-5-preview/** sites/svelte-5-preview/**
# Wasn't checked previously, reenable at some point # Wasn't checked previously, reenable at some point
sites/svelte.dev/** sites/svelte.dev/**

@ -13,7 +13,7 @@ packages/svelte/tests/**/shards/*.test.js
packages/svelte/tests/hydration/samples/*/_expected.html packages/svelte/tests/hydration/samples/*/_expected.html
packages/svelte/tests/hydration/samples/*/_override.html packages/svelte/tests/hydration/samples/*/_override.html
packages/svelte/types packages/svelte/types
packages/svelte/compiler.cjs packages/svelte/compiler/index.js
playgrounds/demo/src playgrounds/demo/src
playgrounds/sandbox/input/**.svelte playgrounds/sandbox/input/**.svelte
playgrounds/sandbox/output playgrounds/sandbox/output

@ -1,6 +1,6 @@
/types/*.map /types/*.map
/types/compiler /types/compiler
/compiler.cjs /compiler/index.js
/action.d.ts /action.d.ts
/animate.d.ts /animate.d.ts

@ -0,0 +1,3 @@
{
"type": "commonjs"
}

@ -12,7 +12,7 @@
"src", "src",
"!src/**/*.test.*", "!src/**/*.test.*",
"types", "types",
"compiler.cjs", "compiler/index.js",
"*.d.ts", "*.d.ts",
"README.md" "README.md"
], ],
@ -34,7 +34,7 @@
}, },
"./compiler": { "./compiler": {
"types": "./types/index.d.ts", "types": "./types/index.d.ts",
"require": "./compiler.cjs", "require": "./compiler/index.js",
"default": "./src/compiler/index.js" "default": "./src/compiler/index.js"
}, },
"./easing": { "./easing": {

@ -9,7 +9,7 @@ import './scripts/generate-version.js';
export default defineConfig({ export default defineConfig({
input: 'src/compiler/index.js', input: 'src/compiler/index.js',
output: { output: {
file: 'compiler.cjs', file: 'compiler/index.js',
format: 'umd', format: 'umd',
name: 'svelte' name: 'svelte'
}, },

@ -48,10 +48,8 @@ self.addEventListener(
const { version } = await fetch(`${svelte_url}/package.json`).then((r) => r.json()); const { version } = await fetch(`${svelte_url}/package.json`).then((r) => r.json());
console.log(`Using Svelte compiler version ${version}`); console.log(`Using Svelte compiler version ${version}`);
// unpkg doesn't set the correct MIME type for .cjs files const compiler = await fetch(`${svelte_url}/compiler/index.js`).then((r) => r.text());
// https://github.com/mjackson/unpkg/issues/355 (0, eval)(compiler + '\n//# sourceURL=compiler/index.js@' + version);
const compiler = await fetch(`${svelte_url}/compiler.cjs`).then((r) => r.text());
(0, eval)(compiler + '\n//# sourceURL=compiler.cjs@' + version);
svelte = globalThis.svelte; svelte = globalThis.svelte;

@ -29,10 +29,8 @@ self.addEventListener(
.then((r) => r.json()) .then((r) => r.json())
.catch(() => ({ version: 'experimental' })); .catch(() => ({ version: 'experimental' }));
// unpkg doesn't set the correct MIME type for .cjs files const compiler = await fetch(`${svelte_url}/compiler/index.js`).then((r) => r.text());
// https://github.com/mjackson/unpkg/issues/355 (0, eval)(compiler + '\n//# sourceURL=compiler/index.js@' + version);
const compiler = await fetch(`${svelte_url}/compiler.cjs`).then((r) => r.text());
(0, eval)(compiler + '\n//# sourceURL=compiler.cjs@' + version);
svelte = globalThis.svelte; svelte = globalThis.svelte;

@ -1,4 +1,4 @@
import compiler_cjs from '../../../../../../packages/svelte/compiler.cjs?url'; import compiler_cjs from '../../../../../../packages/svelte/compiler/index.js?url';
import package_json from '../../../../../../packages/svelte/package.json?url'; import package_json from '../../../../../../packages/svelte/package.json?url';
import { read } from '$app/server'; import { read } from '$app/server';
@ -14,14 +14,14 @@ export const prerender = true;
export function entries() { export function entries() {
const entries = Object.keys(files).map((path) => ({ path: path.replace(prefix, '') })); const entries = Object.keys(files).map((path) => ({ path: path.replace(prefix, '') }));
entries.push({ path: 'compiler.cjs' }, { path: 'package.json' }); entries.push({ path: 'compiler/index.js' }, { path: 'package.json' });
return entries; return entries;
} }
// service worker requests files under this path to load the compiler and runtime // service worker requests files under this path to load the compiler and runtime
export async function GET({ params }) { export async function GET({ params }) {
let url = ''; let url = '';
if (params.path === 'compiler.cjs') { if (params.path === 'compiler/index.js') {
url = compiler_cjs; url = compiler_cjs;
} else if (params.path === 'package.json') { } else if (params.path === 'package.json') {
url = package_json; url = package_json;

Loading…
Cancel
Save