dont try to be clever with module interop

pull/1864/head
Rich Harris 7 years ago
parent 210173e429
commit 6fd8fbf40b

@ -1,9 +1,9 @@
import jsdom from 'jsdom'; import * as jsdom from 'jsdom';
import assert from 'assert'; import * as assert from 'assert';
import glob from 'tiny-glob/sync.js'; import * as glob from 'tiny-glob/sync.js';
import fs from 'fs'; import * as fs from 'fs';
import path from 'path'; import * as path from 'path';
import chalk from 'chalk'; import * as chalk from 'chalk';
// for coverage purposes, we need to test source files, // for coverage purposes, we need to test source files,
// but for sanity purposes, we need to test dist files // but for sanity purposes, we need to test dist files

@ -1,6 +1,6 @@
import assert from 'assert'; import * as assert from 'assert';
import path from 'path'; import * as path from 'path';
import fs from 'fs'; import * as fs from 'fs';
import { import {
showOutput, showOutput,

@ -1,4 +1,4 @@
import assert from "assert"; import * as assert from "assert";
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import { loadConfig, svelte } from "../helpers.js"; import { loadConfig, svelte } from "../helpers.js";

@ -1,5 +1,5 @@
import assert from 'assert'; import * as assert from 'assert';
import fs from 'fs'; import * as fs from 'fs';
import { svelte, tryToLoadJson } from '../helpers.js'; import { svelte, tryToLoadJson } from '../helpers.js';
describe('parse', () => { describe('parse', () => {

@ -1,4 +1,4 @@
import assert from 'assert'; import * as assert from 'assert';
import { svelte } from '../helpers.js'; import { svelte } from '../helpers.js';
describe('preprocess', () => { describe('preprocess', () => {

@ -1,8 +1,8 @@
import assert from "assert"; import * as assert from "assert";
import * as path from "path"; import * as path from "path";
import * as fs from "fs"; import * as fs from "fs";
import { rollup } from 'rollup'; import { rollup } from 'rollup';
import virtual from 'rollup-plugin-virtual'; import * as virtual from 'rollup-plugin-virtual';
import { transitionManager } from "../../internal.js"; import { transitionManager } from "../../internal.js";
import { import {
@ -119,7 +119,7 @@ describe.only("runtime", () => {
mod = require(`./samples/${dir}/main.html`); mod = require(`./samples/${dir}/main.html`);
SvelteComponent = mod.default; SvelteComponent = mod.default;
} catch (err) { } catch (err) {
showOutput(cwd, { internal, hydratable: hydrate }, svelte.compile); // eslint-disable-line no-console showOutput(cwd, { internal, hydratable: hydrate, format: 'cjs' }, svelte.compile); // eslint-disable-line no-console
throw err; throw err;
} }
@ -191,7 +191,8 @@ describe.only("runtime", () => {
showOutput(cwd, { showOutput(cwd, {
internal, internal,
hydratable: hydrate, hydratable: hydrate,
dev: compileOptions.dev dev: compileOptions.dev,
format: 'cjs'
}, svelte.compile); // eslint-disable-line no-console }, svelte.compile); // eslint-disable-line no-console
throw err; throw err;
} }
@ -200,7 +201,8 @@ describe.only("runtime", () => {
if (config.show) { if (config.show) {
showOutput(cwd, { showOutput(cwd, {
internal, internal,
hydratable: hydrate hydratable: hydrate,
format: 'cjs'
}, svelte.compile); }, svelte.compile);
} }

@ -1,7 +1,7 @@
import assert from "assert"; import * as assert from "assert";
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import glob from 'tiny-glob/sync.js'; import * as glob from 'tiny-glob/sync.js';
import { import {
showOutput, showOutput,

@ -8,9 +8,10 @@ require.extensions['.js'] = function(module, filename) {
const exports = []; const exports = [];
var code = fs.readFileSync(filename, 'utf-8') var code = fs.readFileSync(filename, 'utf-8')
.replace(/^import (?:\* as )?(\w+) from ['"]([^'"]+)['"];?/gm, 'var $1 = require("$2");') .replace(/^import \* as (\w+) from ['"]([^'"]+)['"];?/gm, 'var $1 = require("$2");')
.replace(/^import (\w+) from ['"]([^'"]+)['"];?/gm, 'var {default: $1} = require("$2");')
.replace(/^import {([^}]+)} from ['"](.+)['"];?/gm, 'var {$1} = require("$2");') .replace(/^import {([^}]+)} from ['"](.+)['"];?/gm, 'var {$1} = require("$2");')
.replace(/^export default /gm, 'module.exports = ') .replace(/^export default /gm, 'exports.default = ')
.replace(/^export (const|let|var|class|function) (\w+)/gm, (match, type, name) => { .replace(/^export (const|let|var|class|function) (\w+)/gm, (match, type, name) => {
exports.push(name); exports.push(name);
return `${type} ${name}`; return `${type} ${name}`;

@ -1,6 +1,6 @@
import * as fs from "fs"; import * as fs from "fs";
import * as path from "path"; import * as path from "path";
import assert from "assert"; import * as assert from "assert";
import { loadConfig, svelte } from "../helpers.js"; import { loadConfig, svelte } from "../helpers.js";
import { SourceMapConsumer } from "source-map"; import { SourceMapConsumer } from "source-map";
import { getLocator } from "locate-character"; import { getLocator } from "locate-character";

@ -1,5 +1,5 @@
import * as fs from 'fs'; import * as fs from 'fs';
import assert from 'assert'; import * as assert from 'assert';
import { svelte, loadConfig, tryToLoadJson } from '../helpers.js'; import { svelte, loadConfig, tryToLoadJson } from '../helpers.js';
describe('stats', () => { describe('stats', () => {

@ -1,5 +1,5 @@
import * as fs from "fs"; import * as fs from "fs";
import assert from "assert"; import * as assert from "assert";
import { svelte, loadConfig, tryToLoadJson } from "../helpers.js"; import { svelte, loadConfig, tryToLoadJson } from "../helpers.js";
describe("validate", () => { describe("validate", () => {

Loading…
Cancel
Save