diff --git a/package-lock.json b/package-lock.json index a980324d8e..d52d33f24b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,7 @@ "mocha": "^10.2.0", "periscopic": "^3.1.0", "puppeteer": "^19.8.5", - "rollup": "^2.79.1", + "rollup": "^3.20.2", "source-map": "^0.7.4", "source-map-support": "^0.5.21", "tiny-glob": "^0.2.9", @@ -909,22 +909,6 @@ "agadoo": "cli.js" } }, - "node_modules/agadoo/node_modules/rollup": { - "version": "3.18.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.18.0.tgz", - "integrity": "sha512-J8C6VfEBjkvYPESMQYxKHxNOh4A5a3FlP+0BETGo34HEcE4eTlgCrO2+eWzlu2a/sHs2QUkZco+wscH7jhhgWg==", - "dev": true, - "bin": { - "rollup": "dist/bin/rollup" - }, - "engines": { - "node": ">=14.18.0", - "npm": ">=8.0.0" - }, - "optionalDependencies": { - "fsevents": "~2.3.2" - } - }, "node_modules/agent-base": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", @@ -4558,34 +4542,21 @@ } }, "node_modules/rollup": { - "version": "2.79.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz", - "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==", + "version": "3.20.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.20.2.tgz", + "integrity": "sha512-3zwkBQl7Ai7MFYQE0y1MeQ15+9jsi7XxfrqwTb/9EK8D9C9+//EBR4M+CuA1KODRaNbFez/lWxA5vhEGZp4MUg==", "dev": true, "bin": { "rollup": "dist/bin/rollup" }, "engines": { - "node": ">=10.0.0" + "node": ">=14.18.0", + "npm": ">=8.0.0" }, "optionalDependencies": { "fsevents": "~2.3.2" } }, - "node_modules/rollup/node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/rrweb-cssom": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.6.0.tgz", @@ -6077,17 +6048,6 @@ "@rollup/plugin-virtual": "^3.0.1", "acorn": "^8.8.1", "rollup": "^3.5.0" - }, - "dependencies": { - "rollup": { - "version": "3.18.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.18.0.tgz", - "integrity": "sha512-J8C6VfEBjkvYPESMQYxKHxNOh4A5a3FlP+0BETGo34HEcE4eTlgCrO2+eWzlu2a/sHs2QUkZco+wscH7jhhgWg==", - "dev": true, - "requires": { - "fsevents": "~2.3.2" - } - } } }, "agent-base": { @@ -8776,21 +8736,12 @@ "dev": true }, "rollup": { - "version": "2.79.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz", - "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==", + "version": "3.20.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.20.2.tgz", + "integrity": "sha512-3zwkBQl7Ai7MFYQE0y1MeQ15+9jsi7XxfrqwTb/9EK8D9C9+//EBR4M+CuA1KODRaNbFez/lWxA5vhEGZp4MUg==", "dev": true, "requires": { "fsevents": "~2.3.2" - }, - "dependencies": { - "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "dev": true, - "optional": true - } } }, "rrweb-cssom": { diff --git a/package.json b/package.json index 13e288e8cb..c5239c8b50 100644 --- a/package.json +++ b/package.json @@ -152,7 +152,7 @@ "mocha": "^10.2.0", "periscopic": "^3.1.0", "puppeteer": "^19.8.5", - "rollup": "^2.79.1", + "rollup": "^3.20.2", "source-map": "^0.7.4", "source-map-support": "^0.5.21", "tiny-glob": "^0.2.9", diff --git a/rollup.config.js b/rollup.config.mjs similarity index 60% rename from rollup.config.js rename to rollup.config.mjs index f054c747c9..56ebdaa755 100644 --- a/rollup.config.js +++ b/rollup.config.mjs @@ -1,24 +1,58 @@ -import fs from 'fs'; +import fs from 'node:fs'; +import { createRequire } from 'node:module'; import replace from '@rollup/plugin-replace'; import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import json from '@rollup/plugin-json'; import sucrase from '@rollup/plugin-sucrase'; import typescript from '@rollup/plugin-typescript'; -import pkg from './package.json'; + +const require = createRequire(import.meta.url); +const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8')); const is_publish = !!process.env.PUBLISH; const ts_plugin = is_publish ? typescript({ - include: 'src/**', typescript: require('typescript') }) : sucrase({ transforms: ['typescript'] }); -const external = id => id.startsWith('svelte/'); +// The following external and path logic is necessary so that the bundled runtime pieces and the index file +// reference each other correctly instead of bundling their references to each other + +/** + * Ensures that relative imports inside `src/runtime` like `./internal` and `../store` are externalized correctly + */ +const external = (id, parent_id) => { + const parent_segments = parent_id.replace(/\\/g, '/').split('/'); + // TODO needs to be adjusted when we move to JS modules + if (parent_segments[parent_segments.length - 3] === 'runtime') { + return /\.\.\/\w+$/.test(id); + } else { + return id === './internal' && parent_segments[parent_segments.length - 2] === 'runtime'; + } +} + +/** + * Transforms externalized import paths like `../store` into correct relative imports with correct index file extension import + */ +const replace_relative_svelte_imports = (id, ending) => { + id = id.replace(/\\/g, '/'); + // TODO needs to be adjusted when we move to JS modules + return /src\/runtime\/\w+$/.test(id) && `../${id.split('/').pop()}/${ending}`; +} + +/** + * Transforms externalized `./internal` import path into correct relative import with correct index file extension import + */ +const replace_relative_internal_import = (id, ending) => { + id = id.replace(/\\/g, '/'); + // TODO needs to be adjusted when we move to JS modules + return id.endsWith('src/runtime/internal') && `./internal/${ending}`; +} fs.writeFileSync(`./compiler.d.ts`, `export { compile, parse, preprocess, walk, VERSION } from './types/compiler/index';`); @@ -30,12 +64,12 @@ export default [ { file: `index.mjs`, format: 'esm', - paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}/index.mjs` + paths: id => replace_relative_internal_import(id, 'index.mjs') }, { file: `index.js`, format: 'cjs', - paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}/index.js` + paths: id => replace_relative_internal_import(id, 'index.js') } ], external, @@ -48,12 +82,12 @@ export default [ { file: `ssr.mjs`, format: 'esm', - paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}/index.mjs` + paths: id => replace_relative_internal_import(id, 'index.mjs') }, { file: `ssr.js`, format: 'cjs', - paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}/index.js` + paths: id => replace_relative_internal_import(id, 'index.js') } ], external, @@ -68,12 +102,12 @@ export default [ { file: `${dir}/index.mjs`, format: 'esm', - paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '..')}/index.mjs` + paths: id => replace_relative_svelte_imports(id, 'index.mjs') }, { file: `${dir}/index.js`, format: 'cjs', - paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '..')}/index.js` + paths: id => replace_relative_svelte_imports(id, 'index.js') } ], external, diff --git a/src/runtime/animate/index.ts b/src/runtime/animate/index.ts index ff73bbc29e..3b422d72fa 100644 --- a/src/runtime/animate/index.ts +++ b/src/runtime/animate/index.ts @@ -1,5 +1,5 @@ -import { cubicOut } from 'svelte/easing'; -import { is_function } from 'svelte/internal'; +import { cubicOut } from '../easing'; +import { is_function } from '../internal'; // todo: same as Transition, should it be shared? export interface AnimationConfig { diff --git a/src/runtime/easing/index.ts b/src/runtime/easing/index.ts index c23019b320..b466ec5840 100644 --- a/src/runtime/easing/index.ts +++ b/src/runtime/easing/index.ts @@ -3,7 +3,7 @@ Adapted from https://github.com/mattdesl Distributed under MIT License https://github.com/mattdesl/eases/blob/master/LICENSE.md */ -export { identity as linear } from 'svelte/internal'; +export { identity as linear } from '../internal'; export function backInOut(t: number) { const s = 1.70158 * 1.525; diff --git a/src/runtime/index.ts b/src/runtime/index.ts index 3bce9163ca..2f8a1ffd12 100644 --- a/src/runtime/index.ts +++ b/src/runtime/index.ts @@ -13,5 +13,5 @@ export { createEventDispatcher, SvelteComponentDev as SvelteComponent, SvelteComponentTyped -} from 'svelte/internal'; -export type { ComponentType, ComponentConstructorOptions, ComponentProps, ComponentEvents } from 'svelte/internal'; +} from './internal'; +export type { ComponentType, ComponentConstructorOptions, ComponentProps, ComponentEvents } from './internal'; diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index 192f40140e..1507bad541 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -1,4 +1,4 @@ -import { Readable } from 'svelte/store'; +import type { Readable } from '../store'; export function noop() {} diff --git a/src/runtime/motion/spring.ts b/src/runtime/motion/spring.ts index 64d17a058b..526d4384f1 100644 --- a/src/runtime/motion/spring.ts +++ b/src/runtime/motion/spring.ts @@ -1,5 +1,5 @@ -import { Readable, writable } from 'svelte/store'; -import { loop, now, Task } from 'svelte/internal'; +import { Readable, writable } from '../store'; +import { loop, now, Task } from '../internal'; import { is_date } from './utils'; interface TickContext { diff --git a/src/runtime/motion/tweened.ts b/src/runtime/motion/tweened.ts index fd83fcb5f5..5e9298011e 100644 --- a/src/runtime/motion/tweened.ts +++ b/src/runtime/motion/tweened.ts @@ -1,6 +1,6 @@ -import { Readable, writable } from 'svelte/store'; -import { assign, loop, now, Task } from 'svelte/internal'; -import { linear } from 'svelte/easing'; +import { Readable, writable } from '../store'; +import { assign, loop, now, Task } from '../internal'; +import { linear } from '../easing'; import { is_date } from './utils'; function get_interpolator(a, b) { diff --git a/src/runtime/store/index.ts b/src/runtime/store/index.ts index 67c2bcb15c..4991c05700 100644 --- a/src/runtime/store/index.ts +++ b/src/runtime/store/index.ts @@ -1,4 +1,4 @@ -import { run_all, subscribe, noop, safe_not_equal, is_function, get_store_value } from 'svelte/internal'; +import { run_all, subscribe, noop, safe_not_equal, is_function, get_store_value } from '../internal'; /** Callback to inform of a value updates. */ export type Subscriber = (value: T) => void; diff --git a/src/runtime/transition/index.ts b/src/runtime/transition/index.ts index 7ea08a02d2..9369e2a801 100644 --- a/src/runtime/transition/index.ts +++ b/src/runtime/transition/index.ts @@ -1,5 +1,5 @@ -import { cubicOut, cubicInOut, linear } from 'svelte/easing'; -import { assign, split_css_unit, is_function } from 'svelte/internal'; +import { cubicOut, cubicInOut, linear } from '../easing'; +import { assign, split_css_unit, is_function } from '../internal'; export type EasingFunction = (t: number) => number; diff --git a/tsconfig.json b/tsconfig.json index 39532bfe48..16d4a70709 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,12 @@ { - "include": [], + "include": ["src/**/*"], "compilerOptions": { "rootDir": "src", // target node v8+ (https://node.green/) // the only missing feature is Array.prototype.values - "lib": ["es2017", "DOM"], + "lib": ["es2017", "DOM", "DOM.Iterable"], "target": "es2017", "declaration": true,