Skip to content

Commit c9ccd6e

Browse files
chore: upgrade rollup (#8491)
bump to rollup 3. Includes reworking the "treat those imports as external" a bit so that Rollup builds correctly but doesn't bundle some of the (now relative) imports --------- Co-authored-by: Simon Holthausen <[email protected]>
1 parent 42e0f7d commit c9ccd6e

File tree

12 files changed

+360
-421
lines changed

12 files changed

+360
-421
lines changed

package-lock.json

Lines changed: 294 additions & 389 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@
121121
"devDependencies": {
122122
"@ampproject/remapping": "^2.2.1",
123123
"@jridgewell/sourcemap-codec": "^1.4.15",
124-
"@rollup/plugin-commonjs": "^11.0.0",
124+
"@rollup/plugin-commonjs": "^24.1.0",
125125
"@rollup/plugin-json": "^6.0.0",
126-
"@rollup/plugin-node-resolve": "^11.2.1",
126+
"@rollup/plugin-node-resolve": "^15.0.2",
127127
"@rollup/plugin-replace": "^5.0.2",
128-
"@rollup/plugin-sucrase": "^3.1.0",
129-
"@rollup/plugin-typescript": "^2.0.1",
128+
"@rollup/plugin-sucrase": "^5.0.1",
129+
"@rollup/plugin-typescript": "^11.1.0",
130130
"@rollup/plugin-virtual": "^3.0.1",
131131
"@sveltejs/eslint-config": "github:sveltejs/eslint-config#v5.8.0",
132132
"@types/aria-query": "^5.0.1",
@@ -152,7 +152,7 @@
152152
"mocha": "^10.2.0",
153153
"periscopic": "^3.1.0",
154154
"puppeteer": "^19.8.5",
155-
"rollup": "^1.27.14",
155+
"rollup": "^3.20.2",
156156
"source-map": "^0.7.4",
157157
"source-map-support": "^0.5.21",
158158
"tiny-glob": "^0.2.9",

rollup.config.js renamed to rollup.config.mjs

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,58 @@
1-
import fs from 'fs';
1+
import fs from 'node:fs';
2+
import { createRequire } from 'node:module';
23
import replace from '@rollup/plugin-replace';
34
import resolve from '@rollup/plugin-node-resolve';
45
import commonjs from '@rollup/plugin-commonjs';
56
import json from '@rollup/plugin-json';
67
import sucrase from '@rollup/plugin-sucrase';
78
import typescript from '@rollup/plugin-typescript';
8-
import pkg from './package.json';
9+
10+
const require = createRequire(import.meta.url);
11+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
912

1013
const is_publish = !!process.env.PUBLISH;
1114

1215
const ts_plugin = is_publish
1316
? typescript({
14-
include: 'src/**',
1517
typescript: require('typescript')
1618
})
1719
: sucrase({
1820
transforms: ['typescript']
1921
});
2022

21-
const external = id => id.startsWith('svelte/');
23+
// The following external and path logic is necessary so that the bundled runtime pieces and the index file
24+
// reference each other correctly instead of bundling their references to each other
25+
26+
/**
27+
* Ensures that relative imports inside `src/runtime` like `./internal` and `../store` are externalized correctly
28+
*/
29+
const external = (id, parent_id) => {
30+
const parent_segments = parent_id.replace(/\\/g, '/').split('/');
31+
// TODO needs to be adjusted when we move to JS modules
32+
if (parent_segments[parent_segments.length - 3] === 'runtime') {
33+
return /\.\.\/\w+$/.test(id);
34+
} else {
35+
return id === './internal' && parent_segments[parent_segments.length - 2] === 'runtime';
36+
}
37+
}
38+
39+
/**
40+
* Transforms externalized import paths like `../store` into correct relative imports with correct index file extension import
41+
*/
42+
const replace_relative_svelte_imports = (id, ending) => {
43+
id = id.replace(/\\/g, '/');
44+
// TODO needs to be adjusted when we move to JS modules
45+
return /src\/runtime\/\w+$/.test(id) && `../${id.split('/').pop()}/${ending}`;
46+
}
47+
48+
/**
49+
* Transforms externalized `./internal` import path into correct relative import with correct index file extension import
50+
*/
51+
const replace_relative_internal_import = (id, ending) => {
52+
id = id.replace(/\\/g, '/');
53+
// TODO needs to be adjusted when we move to JS modules
54+
return id.endsWith('src/runtime/internal') && `./internal/${ending}`;
55+
}
2256

2357
fs.writeFileSync(`./compiler.d.ts`, `export { compile, parse, preprocess, walk, VERSION } from './types/compiler/index';`);
2458

@@ -30,12 +64,12 @@ export default [
3064
{
3165
file: `index.mjs`,
3266
format: 'esm',
33-
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}/index.mjs`
67+
paths: id => replace_relative_internal_import(id, 'index.mjs')
3468
},
3569
{
3670
file: `index.js`,
3771
format: 'cjs',
38-
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}/index.js`
72+
paths: id => replace_relative_internal_import(id, 'index.js')
3973
}
4074
],
4175
external,
@@ -48,12 +82,12 @@ export default [
4882
{
4983
file: `ssr.mjs`,
5084
format: 'esm',
51-
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}/index.mjs`
85+
paths: id => replace_relative_internal_import(id, 'index.mjs')
5286
},
5387
{
5488
file: `ssr.js`,
5589
format: 'cjs',
56-
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}/index.js`
90+
paths: id => replace_relative_internal_import(id, 'index.js')
5791
}
5892
],
5993
external,
@@ -68,12 +102,12 @@ export default [
68102
{
69103
file: `${dir}/index.mjs`,
70104
format: 'esm',
71-
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '..')}/index.mjs`
105+
paths: id => replace_relative_svelte_imports(id, 'index.mjs')
72106
},
73107
{
74108
file: `${dir}/index.js`,
75109
format: 'cjs',
76-
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '..')}/index.js`
110+
paths: id => replace_relative_svelte_imports(id, 'index.js')
77111
}
78112
],
79113
external,
@@ -83,7 +117,7 @@ export default [
83117
}),
84118
ts_plugin,
85119
{
86-
writeBundle(bundle) {
120+
writeBundle(_options, bundle) {
87121
if (dir === 'internal') {
88122
const mod = bundle['index.mjs'];
89123
if (mod) {

src/runtime/animate/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { cubicOut } from 'svelte/easing';
2-
import { is_function } from 'svelte/internal';
1+
import { cubicOut } from '../easing';
2+
import { is_function } from '../internal';
33

44
// todo: same as Transition, should it be shared?
55
export interface AnimationConfig {

src/runtime/easing/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Adapted from https://github.com/mattdesl
33
Distributed under MIT License https://github.com/mattdesl/eases/blob/master/LICENSE.md
44
*/
55

6-
export { identity as linear } from 'svelte/internal';
6+
export { identity as linear } from '../internal';
77

88
export function backInOut(t: number) {
99
const s = 1.70158 * 1.525;

src/runtime/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ export {
1313
createEventDispatcher,
1414
SvelteComponentDev as SvelteComponent,
1515
SvelteComponentTyped
16-
} from 'svelte/internal';
17-
export type { ComponentType, ComponentConstructorOptions, ComponentProps, ComponentEvents } from 'svelte/internal';
16+
} from './internal';
17+
export type { ComponentType, ComponentConstructorOptions, ComponentProps, ComponentEvents } from './internal';

src/runtime/internal/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Readable } from 'svelte/store';
1+
import type { Readable } from '../store';
22

33
export function noop() {}
44

src/runtime/motion/spring.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Readable, writable } from 'svelte/store';
2-
import { loop, now, Task } from 'svelte/internal';
1+
import { Readable, writable } from '../store';
2+
import { loop, now, Task } from '../internal';
33
import { is_date } from './utils';
44

55
interface TickContext<T> {

src/runtime/motion/tweened.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Readable, writable } from 'svelte/store';
2-
import { assign, loop, now, Task } from 'svelte/internal';
3-
import { linear } from 'svelte/easing';
1+
import { Readable, writable } from '../store';
2+
import { assign, loop, now, Task } from '../internal';
3+
import { linear } from '../easing';
44
import { is_date } from './utils';
55

66
function get_interpolator(a, b) {

src/runtime/store/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { run_all, subscribe, noop, safe_not_equal, is_function, get_store_value } from 'svelte/internal';
1+
import { run_all, subscribe, noop, safe_not_equal, is_function, get_store_value } from '../internal';
22

33
/** Callback to inform of a value updates. */
44
export type Subscriber<T> = (value: T) => void;

src/runtime/transition/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { cubicOut, cubicInOut, linear } from 'svelte/easing';
2-
import { assign, split_css_unit, is_function } from 'svelte/internal';
1+
import { cubicOut, cubicInOut, linear } from '../easing';
2+
import { assign, split_css_unit, is_function } from '../internal';
33

44
export type EasingFunction = (t: number) => number;
55

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
2-
"include": [],
2+
"include": ["src/**/*"],
33

44
"compilerOptions": {
55
"rootDir": "src",
66

77
// target node v8+ (https://node.green/)
88
// the only missing feature is Array.prototype.values
9-
"lib": ["es2017", "DOM"],
9+
"lib": ["es2017", "DOM", "DOM.Iterable"],
1010
"target": "es2017",
1111

1212
"declaration": true,

0 commit comments

Comments
 (0)