Skip to content
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

Folder structure #2887

Merged
merged 7 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
/index
mrkishi marked this conversation as resolved.
Show resolved Hide resolved
/internal
/store
/easing
/motion
/transition
/animate
/scratch/
/coverage/
/coverage.lcov/
Expand Down
1 change: 0 additions & 1 deletion animate.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion easing.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion index.d.ts

This file was deleted.

16 changes: 16 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var internal = require('./internal');



exports.onMount = internal.onMount;
exports.onDestroy = internal.onDestroy;
exports.beforeUpdate = internal.beforeUpdate;
exports.afterUpdate = internal.afterUpdate;
exports.setContext = internal.setContext;
exports.getContext = internal.getContext;
exports.tick = internal.tick;
exports.createEventDispatcher = internal.createEventDispatcher;
1 change: 1 addition & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { onMount, onDestroy, beforeUpdate, afterUpdate, setContext, getContext, tick, createEventDispatcher } from './internal';
1 change: 0 additions & 1 deletion internal.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion motion.d.ts

This file was deleted.

18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
"compiler.js",
"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",
Expand All @@ -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"
},
Expand Down
104 changes: 42 additions & 62 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -60,7 +82,7 @@ export default [
include: ['node_modules/**']
}),
json(),
tsPlugin
ts_plugin
],
output: {
file: 'compiler.js',
Expand All @@ -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/')
}))
}
];
12 changes: 12 additions & 0 deletions scripts/create-stubs.js
Original file line number Diff line number Diff line change
@@ -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';`);
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/compile/index.ts → src/compiler/compile/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assign } from '../internal/index';
import { assign } from '../../runtime/internal/index';
import Stats from '../Stats';
import parse from '../parse/index';
import render_dom from './render-dom/index';
Expand Down
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.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Block from '../../render-dom/Block';
import Component from './../../Component';
import Component from '../../Component';
import Node from './Node';
import { INode } from '../interfaces';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Attribute from './../Attribute';
import Component from './../../Component';
import Attribute from '../Attribute';
import Component from '../../Component';
import { INode } from '../interfaces';
import Text from '../Text';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Binding from '../../../nodes/Binding';
import ElementWrapper from '.';
import ElementWrapper from '../Element';
import { dimensions } from '../../../../utils/patterns';
import get_object from '../../../utils/get_object';
import Block from '../../Block';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Attribute from '../../../nodes/Attribute';
import Block from '../../Block';
import AttributeWrapper from './Attribute';
import ElementWrapper from '.';
import ElementWrapper from '../Element';
import { stringify } from '../../../utils/stringify';
import add_to_set from '../../../utils/add_to_set';
import Expression from '../../../nodes/shared/Expression';
Expand Down
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.
2 changes: 1 addition & 1 deletion src/utils/error.ts → src/compiler/utils/error.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { locate } from 'locate-character';
import get_code_frame from '../utils/get_code_frame';
import get_code_frame from './get_code_frame';

class CompileError extends Error {
code: string;
Expand Down
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.
File renamed without changes.
1 change: 0 additions & 1 deletion store.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions test/custom-elements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('custom-elements', function() {

const solo = /\.solo$/.test(dir);
const skip = /\.skip$/.test(dir);
const internal = path.resolve('internal.mjs');
const internal = path.resolve('internal/index.mjs');
const index = path.resolve('index.mjs');
const warnings = [];

Expand All @@ -71,7 +71,7 @@ describe('custom-elements', function() {
plugins: [
{
resolveId(importee) {
if (importee === 'svelte/internal') {
if (importee === 'svelte/internal' || importee === './internal') {
return internal;
}

Expand Down
6 changes: 3 additions & 3 deletions test/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from "path";
import * as fs from "fs";
import { rollup } from 'rollup';
import * as virtual from 'rollup-plugin-virtual';
import { clear_loops, set_now, set_raf } from "../../internal.js";
import { clear_loops, set_now, set_raf } from "../../internal";

import {
showOutput,
Expand All @@ -20,7 +20,7 @@ let compileOptions = null;
let compile = null;

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

describe("runtime", () => {
before(() => {
Expand Down Expand Up @@ -223,7 +223,7 @@ describe("runtime", () => {
{
resolveId: (importee, importer) => {
if (importee.startsWith('svelte/')) {
return importee.replace('svelte', process.cwd()) + '.mjs';
return importee.replace('svelte', process.cwd()) + '/index.mjs';
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/runtime/samples/prop-subscribable/_config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writable } from '../../../../store.js';
import { writable } from '../../../../store';

export default {
props: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writable } from '../../../../store.js';
import { writable } from '../../../../store';

const c = writable(0);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { writable } from '../../../../store.js';
import { writable } from '../../../../store';

const a = writable();
const b = writable();
Expand Down
2 changes: 1 addition & 1 deletion test/runtime/samples/store-assignment-updates/_config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writable } from '../../../../store.js';
import { writable } from '../../../../store';

export default {
props: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writable } from '../../../../store.js';
import { writable } from '../../../../store';

export default {
props: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writable } from '../../../../store.js';
import { writable } from '../../../../store';

export default {
skip: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writable } from '../../../../store.js';
import { writable } from '../../../../store';

export default {
props: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writable } from '../../../../store.js';
import { writable } from '../../../../store';

const count = writable(0);

Expand Down
2 changes: 1 addition & 1 deletion test/runtime/samples/store-auto-subscribe/_config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writable } from '../../../../store.js';
import { writable } from '../../../../store';

export default {
props: {
Expand Down
2 changes: 1 addition & 1 deletion test/runtime/samples/store-contextual/_config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writable } from '../../../../store.js';
import { writable } from '../../../../store';

const todos = [
writable({ done: false, text: 'write docs' }),
Expand Down
Loading