Skip to content

Commit 767ce22

Browse files
authored
Merge pull request #2887 from sveltejs/folder-structure
Folder structure
2 parents 9ac8c66 + 7e3b91e commit 767ce22

File tree

181 files changed

+103
-120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+103
-120
lines changed

.gitignore

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
.nyc_output
44
node_modules
55
*.map
6-
/src/compile/internal-exports.ts
6+
/src/compiler/compile/internal-exports.ts
77
/compiler.*js
88
/index.*js
9-
/internal.*js
10-
/store.*js
11-
/easing.*js
12-
/motion.*js
13-
/transition.*js
14-
/animate.*js
9+
/internal
10+
/store
11+
/easing
12+
/motion
13+
/transition
14+
/animate
1515
/scratch/
1616
/coverage/
1717
/coverage.lcov/

animate.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

easing.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

index.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

motion.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
"compiler.*",
1010
"register.js",
1111
"index.*",
12-
"internal.*",
13-
"store.*",
14-
"animate.*",
15-
"transition.*",
16-
"easing.*",
17-
"motion.*",
12+
"internal",
13+
"store",
14+
"animate",
15+
"transition",
16+
"easing",
17+
"motion",
1818
"svelte",
1919
"README.md"
2020
],
21+
"types": "types/runtime",
2122
"scripts": {
2223
"test": "mocha --opts mocha.opts",
2324
"test:unit": "mocha --require sucrase/register --recursive ./**/__test__.ts",
@@ -30,8 +31,9 @@
3031
"prepare": "npm run build && npm run tsd",
3132
"dev": "rollup -cw",
3233
"pretest": "npm run build",
33-
"posttest": "agadoo internal.mjs",
34-
"prepublishOnly": "export PUBLISH=true && npm test",
34+
"posttest": "agadoo internal/index.mjs",
35+
"prepublishOnly": "export PUBLISH=true && npm test && npm run create-stubs",
36+
"create-stubs": "node scripts/create-stubs.js",
3537
"tsd": "tsc -p . --emitDeclarationOnly",
3638
"typecheck": "tsc -p . --noEmit"
3739
},

rollup.config.js

Lines changed: 42 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import pkg from './package.json';
99

1010
const is_publish = !!process.env.PUBLISH;
1111

12-
const tsPlugin = is_publish
12+
const ts_plugin = is_publish
1313
? typescript({
1414
include: 'src/**',
1515
typescript: require('typescript')
@@ -18,39 +18,61 @@ const tsPlugin = is_publish
1818
transforms: ['typescript']
1919
});
2020

21+
const external = id => id.startsWith('svelte/');
22+
2123
export default [
22-
/* internal.[m]js */
24+
/* runtime */
2325
{
24-
input: `src/internal/index.ts`,
26+
input: `src/runtime/index.ts`,
2527
output: [
2628
{
27-
file: `internal.mjs`,
29+
file: `index.mjs`,
2830
format: 'esm',
29-
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
31+
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}`
3032
},
3133
{
32-
file: `internal.js`,
34+
file: `index.js`,
3335
format: 'cjs',
34-
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
36+
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '.')}`
3537
}
3638
],
37-
external: id => id.startsWith('svelte/'),
39+
external,
40+
plugins: [ts_plugin]
41+
},
3842

39-
plugins: [
40-
tsPlugin,
41-
{
42-
generateBundle(options, bundle) {
43-
const mod = bundle['internal.mjs'];
44-
if (mod) {
45-
fs.writeFileSync('src/compile/internal-exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`);
43+
...fs.readdirSync('src/runtime')
44+
.filter(dir => fs.statSync(`src/runtime/${dir}`).isDirectory())
45+
.map(dir => ({
46+
input: `src/runtime/${dir}/index.ts`,
47+
output: [
48+
{
49+
file: `${dir}/index.mjs`,
50+
format: 'esm',
51+
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '..')}`
52+
},
53+
{
54+
file: `${dir}/index.js`,
55+
format: 'cjs',
56+
paths: id => id.startsWith('svelte/') && `${id.replace('svelte', '..')}`
57+
}
58+
],
59+
external,
60+
plugins: [
61+
ts_plugin,
62+
dir === 'internal' && {
63+
generateBundle(options, bundle) {
64+
const mod = bundle['index.mjs'];
65+
if (mod) {
66+
fs.writeFileSync('src/compiler/compile/internal-exports.ts', `// This file is automatically generated\nexport default new Set(${JSON.stringify(mod.exports)});`);
67+
}
4668
}
4769
}
48-
}]
49-
},
70+
]
71+
})),
5072

5173
/* compiler.js */
5274
{
53-
input: 'src/compiler.ts',
75+
input: 'src/compiler/index.ts',
5476
plugins: [
5577
replace({
5678
__VERSION__: pkg.version
@@ -60,7 +82,7 @@ export default [
6082
include: ['node_modules/**']
6183
}),
6284
json(),
63-
tsPlugin
85+
ts_plugin
6486
],
6587
output: {
6688
file: 'compiler.js',
@@ -71,47 +93,5 @@ export default [
7193
external: is_publish
7294
? []
7395
: id => id === 'acorn' || id === 'magic-string' || id.startsWith('css-tree')
74-
},
75-
76-
/* motion.mjs */
77-
{
78-
input: `src/motion/index.ts`,
79-
output: [
80-
{
81-
file: `motion.mjs`,
82-
format: 'esm',
83-
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
84-
},
85-
{
86-
file: `motion.js`,
87-
format: 'cjs',
88-
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
89-
}
90-
],
91-
plugins: [
92-
tsPlugin
93-
],
94-
external: id => id.startsWith('svelte/')
95-
},
96-
97-
// everything else
98-
...['index', 'easing', 'transition', 'animate', 'store'].map(name => ({
99-
input: `src/${name}.ts`,
100-
output: [
101-
{
102-
file: `${name}.mjs`,
103-
format: 'esm',
104-
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
105-
},
106-
{
107-
file: `${name}.js`,
108-
format: 'cjs',
109-
paths: id => id.startsWith('svelte/') && id.replace('svelte', '.')
110-
}
111-
],
112-
plugins: [
113-
tsPlugin
114-
],
115-
external: id => id.startsWith('svelte/')
116-
}))
96+
}
11797
];

scripts/create-stubs.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const fs = require('fs');
2+
3+
fs.readdirSync('src/runtime')
4+
.filter(dir => fs.statSync(`src/runtime/${dir}`).isDirectory())
5+
.forEach(dir => {
6+
fs.writeFileSync(`${dir}/package.json`, JSON.stringify({
7+
main: './index.js',
8+
module: './index.mjs'
9+
}, null, ' '));
10+
11+
fs.writeFileSync(`${dir}/index.d.ts`, `export * from '../types/runtime/${dir}/index.d.ts';`);
12+
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/compile/index.ts renamed to src/compiler/compile/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assign } from '../internal/index';
1+
import { assign } from '../../runtime/internal/index';
22
import Stats from '../Stats';
33
import parse from '../parse/index';
44
import render_dom from './render-dom/index';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/compile/nodes/shared/AbstractBlock.ts renamed to src/compiler/compile/nodes/shared/AbstractBlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Block from '../../render-dom/Block';
2-
import Component from './../../Component';
2+
import Component from '../../Component';
33
import Node from './Node';
44
import { INode } from '../interfaces';
55

src/compile/nodes/shared/Node.ts renamed to src/compiler/compile/nodes/shared/Node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Attribute from './../Attribute';
2-
import Component from './../../Component';
1+
import Attribute from '../Attribute';
2+
import Component from '../../Component';
33
import { INode } from '../interfaces';
44
import Text from '../Text';
55

src/compile/render-dom/wrappers/Element/Binding.ts renamed to src/compiler/compile/render-dom/wrappers/Element/Binding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Binding from '../../../nodes/Binding';
2-
import ElementWrapper from '.';
2+
import ElementWrapper from '../Element';
33
import { dimensions } from '../../../../utils/patterns';
44
import get_object from '../../../utils/get_object';
55
import Block from '../../Block';

src/compile/render-dom/wrappers/Element/StyleAttribute.ts renamed to src/compiler/compile/render-dom/wrappers/Element/StyleAttribute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Attribute from '../../../nodes/Attribute';
22
import Block from '../../Block';
33
import AttributeWrapper from './Attribute';
4-
import ElementWrapper from '.';
4+
import ElementWrapper from '../Element';
55
import { stringify } from '../../../utils/stringify';
66
import add_to_set from '../../../utils/add_to_set';
77
import Expression from '../../../nodes/shared/Expression';
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/utils/error.ts renamed to src/compiler/utils/error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { locate } from 'locate-character';
2-
import get_code_frame from '../utils/get_code_frame';
2+
import get_code_frame from './get_code_frame';
33

44
class CompileError extends Error {
55
code: string;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

store.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/custom-elements/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('custom-elements', function() {
5858

5959
const solo = /\.solo$/.test(dir);
6060
const skip = /\.skip$/.test(dir);
61-
const internal = path.resolve('internal.mjs');
61+
const internal = path.resolve('internal/index.mjs');
6262
const index = path.resolve('index.mjs');
6363
const warnings = [];
6464

@@ -71,7 +71,7 @@ describe('custom-elements', function() {
7171
plugins: [
7272
{
7373
resolveId(importee) {
74-
if (importee === 'svelte/internal') {
74+
if (importee === 'svelte/internal' || importee === './internal') {
7575
return internal;
7676
}
7777

test/runtime/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from "path";
33
import * as fs from "fs";
44
import { rollup } from 'rollup';
55
import * as virtual from 'rollup-plugin-virtual';
6-
import { clear_loops, set_now, set_raf } from "../../internal.js";
6+
import { clear_loops, set_now, set_raf } from "../../internal";
77

88
import {
99
showOutput,
@@ -20,7 +20,7 @@ let compileOptions = null;
2020
let compile = null;
2121

2222
const sveltePath = process.cwd().split('\\').join('/');
23-
const internal = `${sveltePath}/internal.js`;
23+
const internal = `${sveltePath}/internal`;
2424

2525
describe("runtime", () => {
2626
before(() => {
@@ -223,7 +223,7 @@ describe("runtime", () => {
223223
{
224224
resolveId: (importee, importer) => {
225225
if (importee.startsWith('svelte/')) {
226-
return importee.replace('svelte', process.cwd()) + '.mjs';
226+
return importee.replace('svelte', process.cwd()) + '/index.mjs';
227227
}
228228
}
229229
}

test/runtime/samples/prop-subscribable/_config.js

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

33
export default {
44
props: {

test/runtime/samples/store-assignment-updates-reactive/_config.js

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

33
const c = writable(0);
44

test/runtime/samples/store-assignment-updates-reactive/main.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { writable } from '../../../../store.js';
2+
import { writable } from '../../../../store';
33
44
const a = writable();
55
const b = writable();

test/runtime/samples/store-assignment-updates/_config.js

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

33
export default {
44
props: {

test/runtime/samples/store-auto-subscribe-implicit/_config.js

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

33
export default {
44
props: {

test/runtime/samples/store-auto-subscribe-in-each/_config.js

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

33
export default {
44
skip: true,

test/runtime/samples/store-auto-subscribe-in-reactive-declaration/_config.js

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

33
export default {
44
props: {

test/runtime/samples/store-auto-subscribe-in-script/_config.js

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

33
const count = writable(0);
44

test/runtime/samples/store-auto-subscribe/_config.js

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

33
export default {
44
props: {

test/runtime/samples/store-contextual/_config.js

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

33
const todos = [
44
writable({ done: false, text: 'write docs' }),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { writable } from '../../../../store.js';
1+
import { writable } from '../../../../store';
22

33
export default writable(42);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { writable } from '../../../../store.js';
1+
import { writable } from '../../../../store';
22

33
export default writable(42);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { writable } from '../../../../store.js';
1+
import { writable } from '../../../../store';
22

33
export default writable(42);

0 commit comments

Comments
 (0)