Merge pull request #2887 from sveltejs/folder-structure

Folder structure
pull/2902/head
Rich Harris 6 years ago committed by GitHub
commit 767ce22ed1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

14
.gitignore vendored

@ -3,15 +3,15 @@
.nyc_output .nyc_output
node_modules node_modules
*.map *.map
/src/compile/internal-exports.ts /src/compiler/compile/internal-exports.ts
/compiler.*js /compiler.*js
/index.*js /index.*js
/internal.*js /internal
/store.*js /store
/easing.*js /easing
/motion.*js /motion
/transition.*js /transition
/animate.*js /animate
/scratch/ /scratch/
/coverage/ /coverage/
/coverage.lcov/ /coverage.lcov/

1
animate.d.ts vendored

@ -1 +0,0 @@
export * from './types/animate';

1
easing.d.ts vendored

@ -1 +0,0 @@
export * from './types/easing';

1
index.d.ts vendored

@ -1 +0,0 @@
export * from './types/index';

1
internal.d.ts vendored

@ -1 +0,0 @@
export * from './types/internal';

1
motion.d.ts vendored

@ -1 +0,0 @@
export * from './types/motion';

@ -9,15 +9,16 @@
"compiler.*", "compiler.*",
"register.js", "register.js",
"index.*", "index.*",
"internal.*", "internal",
"store.*", "store",
"animate.*", "animate",
"transition.*", "transition",
"easing.*", "easing",
"motion.*", "motion",
"svelte", "svelte",
"README.md" "README.md"
], ],
"types": "types/runtime",
"scripts": { "scripts": {
"test": "mocha --opts mocha.opts", "test": "mocha --opts mocha.opts",
"test:unit": "mocha --require sucrase/register --recursive ./**/__test__.ts", "test:unit": "mocha --require sucrase/register --recursive ./**/__test__.ts",
@ -30,8 +31,9 @@
"prepare": "npm run build && npm run tsd", "prepare": "npm run build && npm run tsd",
"dev": "rollup -cw", "dev": "rollup -cw",
"pretest": "npm run build", "pretest": "npm run build",
"posttest": "agadoo internal.mjs", "posttest": "agadoo internal/index.mjs",
"prepublishOnly": "export PUBLISH=true && npm test", "prepublishOnly": "export PUBLISH=true && npm test && npm run create-stubs",
"create-stubs": "node scripts/create-stubs.js",
"tsd": "tsc -p . --emitDeclarationOnly", "tsd": "tsc -p . --emitDeclarationOnly",
"typecheck": "tsc -p . --noEmit" "typecheck": "tsc -p . --noEmit"
}, },

@ -9,7 +9,7 @@ import pkg from './package.json';
const is_publish = !!process.env.PUBLISH; const is_publish = !!process.env.PUBLISH;
const tsPlugin = is_publish const ts_plugin = is_publish
? typescript({ ? typescript({
include: 'src/**', include: 'src/**',
typescript: require('typescript') typescript: require('typescript')
@ -18,39 +18,61 @@ const tsPlugin = is_publish
transforms: ['typescript'] transforms: ['typescript']
}); });
const external = id => id.startsWith('svelte/');
export default [ export default [
/* internal.[m]js */ /* runtime */
{ {
input: `src/internal/index.ts`, input: `src/runtime/index.ts`,
output: [ output: [
{ {
file: `internal.mjs`, file: `index.mjs`,
format: 'esm', 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', 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: [ ...fs.readdirSync('src/runtime')
tsPlugin, .filter(dir => fs.statSync(`src/runtime/${dir}`).isDirectory())
{ .map(dir => ({
generateBundle(options, bundle) { input: `src/runtime/${dir}/index.ts`,
const mod = bundle['internal.mjs']; output: [
if (mod) { {
fs.writeFileSync('src/compile/internal-exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`); 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 */ /* compiler.js */
{ {
input: 'src/compiler.ts', input: 'src/compiler/index.ts',
plugins: [ plugins: [
replace({ replace({
__VERSION__: pkg.version __VERSION__: pkg.version
@ -60,7 +82,7 @@ export default [
include: ['node_modules/**'] include: ['node_modules/**']
}), }),
json(), json(),
tsPlugin ts_plugin
], ],
output: { output: {
file: 'compiler.js', file: 'compiler.js',
@ -71,47 +93,5 @@ export default [
external: is_publish external: is_publish
? [] ? []
: id => id === 'acorn' || id === 'magic-string' || id.startsWith('css-tree') : 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/')
}))
]; ];

@ -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';`);
});

@ -1,4 +1,4 @@
import { assign } from '../internal/index'; import { assign } from '../../runtime/internal/index';
import Stats from '../Stats'; import Stats from '../Stats';
import parse from '../parse/index'; import parse from '../parse/index';
import render_dom from './render-dom/index'; import render_dom from './render-dom/index';

@ -1,5 +1,5 @@
import Block from '../../render-dom/Block'; import Block from '../../render-dom/Block';
import Component from './../../Component'; import Component from '../../Component';
import Node from './Node'; import Node from './Node';
import { INode } from '../interfaces'; import { INode } from '../interfaces';

@ -1,5 +1,5 @@
import Attribute from './../Attribute'; import Attribute from '../Attribute';
import Component from './../../Component'; import Component from '../../Component';
import { INode } from '../interfaces'; import { INode } from '../interfaces';
import Text from '../Text'; import Text from '../Text';

@ -1,5 +1,5 @@
import Binding from '../../../nodes/Binding'; import Binding from '../../../nodes/Binding';
import ElementWrapper from '.'; import ElementWrapper from '../Element';
import { dimensions } from '../../../../utils/patterns'; import { dimensions } from '../../../../utils/patterns';
import get_object from '../../../utils/get_object'; import get_object from '../../../utils/get_object';
import Block from '../../Block'; import Block from '../../Block';

@ -1,7 +1,7 @@
import Attribute from '../../../nodes/Attribute'; import Attribute from '../../../nodes/Attribute';
import Block from '../../Block'; import Block from '../../Block';
import AttributeWrapper from './Attribute'; import AttributeWrapper from './Attribute';
import ElementWrapper from '.'; import ElementWrapper from '../Element';
import { stringify } from '../../../utils/stringify'; import { stringify } from '../../../utils/stringify';
import add_to_set from '../../../utils/add_to_set'; import add_to_set from '../../../utils/add_to_set';
import Expression from '../../../nodes/shared/Expression'; import Expression from '../../../nodes/shared/Expression';

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save