Skip to content

chore: upgrade rollup #8491

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 12, 2023
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
683 changes: 294 additions & 389 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@
"devDependencies": {
"@ampproject/remapping": "^2.2.1",
"@jridgewell/sourcemap-codec": "^1.4.15",
"@rollup/plugin-commonjs": "^11.0.0",
"@rollup/plugin-commonjs": "^24.1.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-sucrase": "^3.1.0",
"@rollup/plugin-typescript": "^2.0.1",
"@rollup/plugin-sucrase": "^5.0.1",
"@rollup/plugin-typescript": "^11.1.0",
"@rollup/plugin-virtual": "^3.0.1",
"@sveltejs/eslint-config": "github:sveltejs/eslint-config#v5.8.0",
"@types/aria-query": "^5.0.1",
Expand All @@ -152,7 +152,7 @@
"mocha": "^10.2.0",
"periscopic": "^3.1.0",
"puppeteer": "^19.8.5",
"rollup": "^1.27.14",
"rollup": "^3.20.2",
"source-map": "^0.7.4",
"source-map-support": "^0.5.21",
"tiny-glob": "^0.2.9",
Expand Down
56 changes: 45 additions & 11 deletions rollup.config.js → rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -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';`);

Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -83,7 +117,7 @@ export default [
}),
ts_plugin,
{
writeBundle(bundle) {
writeBundle(_options, bundle) {
if (dir === 'internal') {
const mod = bundle['index.mjs'];
if (mod) {
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/animate/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/easing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
2 changes: 1 addition & 1 deletion src/runtime/internal/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Readable } from 'svelte/store';
import type { Readable } from '../store';

export function noop() {}

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/motion/spring.ts
Original file line number Diff line number Diff line change
@@ -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<T> {
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/motion/tweened.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/store/index.ts
Original file line number Diff line number Diff line change
@@ -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<T> = (value: T) => void;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/transition/index.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down