diff --git a/.gitignore b/.gitignore index 847d12a540..4d7bbc7ac3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,15 +3,15 @@ .nyc_output node_modules *.map -/src/compile/internal-exports.ts +/src/compiler/compile/internal-exports.ts /compiler.*js /index.*js -/internal.*js -/store.*js -/easing.*js -/motion.*js -/transition.*js -/animate.*js +/internal +/store +/easing +/motion +/transition +/animate /scratch/ /coverage/ /coverage.lcov/ @@ -29,5 +29,6 @@ _actual*.* /site/.sessions /site/static/svelte-app.json /site/static/contributors.jpg +/site/static/workers /site/scripts/svelte-app /site/src/routes/_contributors.js diff --git a/animate.d.ts b/animate.d.ts deleted file mode 100644 index e0c5aebb0e..0000000000 --- a/animate.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './types/animate'; diff --git a/easing.d.ts b/easing.d.ts deleted file mode 100644 index 9af6dd9ca7..0000000000 --- a/easing.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './types/easing'; diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index a3d3b4a0d6..0000000000 --- a/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './types/index'; diff --git a/internal.d.ts b/internal.d.ts deleted file mode 100644 index 135ffe7611..0000000000 --- a/internal.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './types/internal'; diff --git a/motion.d.ts b/motion.d.ts deleted file mode 100644 index 4cc764a2c9..0000000000 --- a/motion.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './types/motion'; diff --git a/package.json b/package.json index c39db34df5..6d4bfb134e 100644 --- a/package.json +++ b/package.json @@ -6,18 +6,19 @@ "main": "index", "files": [ "types", - "compiler.js", + "compiler.*", "register.js", "index.*", - "internal.*", - "store.*", - "animate.*", - "transition.*", - "easing.*", - "motion.*", + "internal", + "store", + "animate", + "transition", + "easing", + "motion", "svelte", "README.md" ], + "types": "types/runtime", "scripts": { "test": "mocha --opts mocha.opts", "test:unit": "mocha --require sucrase/register --recursive ./**/__test__.ts", @@ -30,8 +31,9 @@ "prepare": "npm run build && npm run tsd", "dev": "rollup -cw", "pretest": "npm run build", - "posttest": "agadoo internal.mjs", - "prepublishOnly": "export PUBLISH=true && npm test", + "posttest": "agadoo internal/index.mjs", + "prepublishOnly": "export PUBLISH=true && npm test && npm run create-stubs", + "create-stubs": "node scripts/create-stubs.js", "tsd": "tsc -p . --emitDeclarationOnly", "typecheck": "tsc -p . --noEmit" }, diff --git a/rollup.config.js b/rollup.config.js index 9fd49f3e8f..8907ae4e6c 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -9,7 +9,7 @@ import pkg from './package.json'; const is_publish = !!process.env.PUBLISH; -const tsPlugin = is_publish +const ts_plugin = is_publish ? typescript({ include: 'src/**', typescript: require('typescript') @@ -18,39 +18,61 @@ const tsPlugin = is_publish transforms: ['typescript'] }); +const external = id => id.startsWith('svelte/'); + export default [ - /* internal.[m]js */ + /* runtime */ { - input: `src/internal/index.ts`, + input: `src/runtime/index.ts`, output: [ { - file: `internal.mjs`, + file: `index.mjs`, format: 'esm', - paths: id => id.startsWith('svelte/') && id.replace('svelte', '.') + paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}` }, { - file: `internal.js`, + file: `index.js`, format: 'cjs', - paths: id => id.startsWith('svelte/') && id.replace('svelte', '.') + paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}` } ], - external: id => id.startsWith('svelte/'), + external, + plugins: [ts_plugin] + }, - plugins: [ - tsPlugin, - { - generateBundle(options, bundle) { - const mod = bundle['internal.mjs']; - if (mod) { - fs.writeFileSync('src/compile/internal-exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`); + ...fs.readdirSync('src/runtime') + .filter(dir => fs.statSync(`src/runtime/${dir}`).isDirectory()) + .map(dir => ({ + input: `src/runtime/${dir}/index.ts`, + output: [ + { + file: `${dir}/index.mjs`, + format: 'esm', + paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '..')}` + }, + { + file: `${dir}/index.js`, + format: 'cjs', + paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '..')}` + } + ], + external, + plugins: [ + ts_plugin, + dir === 'internal' && { + generateBundle(options, bundle) { + const mod = bundle['index.mjs']; + if (mod) { + fs.writeFileSync('src/compiler/compile/internal-exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`); + } } } - }] - }, + ] + })), /* compiler.js */ { - input: 'src/compiler.ts', + input: 'src/compiler/index.ts', plugins: [ replace({ __VERSION__: pkg.version @@ -60,7 +82,7 @@ export default [ include: ['node_modules/**'] }), json(), - tsPlugin + ts_plugin ], output: { file: 'compiler.js', @@ -71,47 +93,5 @@ export default [ external: is_publish ? [] : id => id === 'acorn' || id === 'magic-string' || id.startsWith('css-tree') - }, - - /* motion.mjs */ - { - input: `src/motion/index.ts`, - output: [ - { - file: `motion.mjs`, - format: 'esm', - paths: id => id.startsWith('svelte/') && id.replace('svelte', '.') - }, - { - file: `motion.js`, - format: 'cjs', - paths: id => id.startsWith('svelte/') && id.replace('svelte', '.') - } - ], - plugins: [ - tsPlugin - ], - external: id => id.startsWith('svelte/') - }, - - // everything else - ...['index', 'easing', 'transition', 'animate', 'store'].map(name => ({ - input: `src/${name}.ts`, - output: [ - { - file: `${name}.mjs`, - format: 'esm', - paths: id => id.startsWith('svelte/') && id.replace('svelte', '.') - }, - { - file: `${name}.js`, - format: 'cjs', - paths: id => id.startsWith('svelte/') && id.replace('svelte', '.') - } - ], - plugins: [ - tsPlugin - ], - external: id => id.startsWith('svelte/') - })) + } ]; diff --git a/scripts/create-stubs.js b/scripts/create-stubs.js new file mode 100644 index 0000000000..191b86cbfd --- /dev/null +++ b/scripts/create-stubs.js @@ -0,0 +1,12 @@ +const fs = require('fs'); + +fs.readdirSync('src/runtime') + .filter(dir => fs.statSync(`src/runtime/${dir}`).isDirectory()) + .forEach(dir => { + fs.writeFileSync(`${dir}/package.json`, JSON.stringify({ + main: './index.js', + module: './index.mjs' + }, null, ' ')); + + fs.writeFileSync(`${dir}/index.d.ts`, `export * from '../types/runtime/${dir}/index.d.ts';`); + }); \ No newline at end of file diff --git a/site/content/docs/03-run-time.md b/site/content/docs/03-run-time.md index 1beacc4169..6db20b5d14 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -618,13 +618,13 @@ Slides an element in and out. ```html {#if condition} -
- flies in and out +
+ slides in and out
{/if} ``` diff --git a/site/content/examples/06-lifecycle/02-update/App.svelte b/site/content/examples/06-lifecycle/02-update/App.svelte index 373b6dcb6a..3eb2dceb52 100644 --- a/site/content/examples/06-lifecycle/02-update/App.svelte +++ b/site/content/examples/06-lifecycle/02-update/App.svelte @@ -1,5 +1,5 @@