Skip to content

chore: compiler subpackage #10988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/metal-clouds-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

breaking: move compiler.cjs to compiler/index.js
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
**/vite.config.js
**/vite.prod.config.js
**/node_modules
**/compiler/index.js

**/tests/**

Expand All @@ -20,4 +21,4 @@ documentation/**
# contains a fork of the REPL which doesn't adhere to eslint rules
sites/svelte-5-preview/**
# Wasn't checked previously, reenable at some point
sites/svelte.dev/**
sites/svelte.dev/**
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ packages/svelte/tests/hydration/samples/*/_before_head.html
packages/svelte/tests/hydration/samples/*/_after.html
packages/svelte/tests/hydration/samples/*/_after_head.html
packages/svelte/types
packages/svelte/compiler.cjs
packages/svelte/compiler/index.js
playgrounds/demo/src
playgrounds/sandbox/input/**.svelte
playgrounds/sandbox/output
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/types/*.map
/types/compiler
/compiler.cjs
/compiler/index.js

/action.d.ts
/animate.d.ts
Expand Down
3 changes: 3 additions & 0 deletions packages/svelte/compiler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
4 changes: 2 additions & 2 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"src",
"!src/**/*.test.*",
"types",
"compiler.cjs",
"compiler/index.js",
"*.d.ts",
"README.md"
],
Expand All @@ -34,7 +34,7 @@
},
"./compiler": {
"types": "./types/index.d.ts",
"require": "./compiler.cjs",
"require": "./compiler/index.js",
"default": "./src/compiler/index.js"
},
"./easing": {
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import './scripts/generate-version.js';
export default defineConfig({
input: 'src/compiler/index.js',
output: {
file: 'compiler.cjs',
file: 'compiler/index.js',
format: 'umd',
name: 'svelte'
},
Expand Down
6 changes: 2 additions & 4 deletions sites/svelte-5-preview/src/lib/workers/bundler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ self.addEventListener(
const { version } = await fetch(`${svelte_url}/package.json`).then((r) => r.json());
console.log(`Using Svelte compiler version ${version}`);

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

svelte = globalThis.svelte;

Expand Down
6 changes: 2 additions & 4 deletions sites/svelte-5-preview/src/lib/workers/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ self.addEventListener(
.then((r) => r.json())
.catch(() => ({ version: 'experimental' }));

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

svelte = globalThis.svelte;

Expand Down
9 changes: 5 additions & 4 deletions sites/svelte-5-preview/src/routes/svelte/[...path]/+server.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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 { read } from '$app/server';

const files = import.meta.glob('../../../../../../packages/svelte/src/**/*.js', {
eager: true,
as: 'url'
query: '?url',
import: 'default'
});

const prefix = '../../../../../../packages/svelte/';
Expand All @@ -13,14 +14,14 @@ export const prerender = true;

export function entries() {
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;
}

// service worker requests files under this path to load the compiler and runtime
export async function GET({ params }) {
let url = '';
if (params.path === 'compiler.cjs') {
if (params.path === 'compiler/index.js') {
url = compiler_cjs;
} else if (params.path === 'package.json') {
url = package_json;
Expand Down