Skip to content

Commit f62c8aa

Browse files
committed
feat: remove babel transpiling, back to plain commonjs
BREAKING CHANGE: ensure-parser-set API is changed.
1 parent f0ac47a commit f62c8aa

66 files changed

Lines changed: 354 additions & 331 deletions

Some content is hidden

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

.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/fixtures/

.eslintrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"extends": "eslint:recommended",
33
"parserOptions": {
4-
"ecmaVersion": 2018,
5-
"sourceType": "module"
4+
"ecmaVersion": 2018
65
},
76
"rules": {
87
"no-console": 0,

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const Bundler = require('./lib');
2+
const ensureParserSet = require('./lib/ensure-parser-set');
3+
Bundler.ensureParserSet = ensureParserSet;
4+
module.exports = Bundler;
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import path from 'path';
2-
import os from 'os';
3-
import fs from 'fs';
4-
import del from 'del';
5-
import mkdirp from 'mkdirp';
1+
const path = require('path');
2+
const os = require('os');
3+
const fs = require('fs');
4+
const del = require('del');
5+
const mkdirp = require('mkdirp');
66

77
const tmpDir = os.tmpdir();
88
const CACHE_DIR = path.resolve(tmpDir, 'dumber');
@@ -13,21 +13,21 @@ function cachedFilePath(hash) {
1313
return path.resolve(CACHE_DIR, folder, fileName);
1414
}
1515

16-
export function getCache(hash) {
16+
exports.getCache = function(hash) {
1717
const filePath = cachedFilePath(hash);
1818
try {
1919
return JSON.parse(fs.readFileSync(filePath));
2020
} catch (e) {
2121
// ignore
2222
}
23-
}
23+
};
2424

25-
export function setCache(hash, object) {
25+
exports.setCache = function(hash, object) {
2626
const filePath = cachedFilePath(hash);
2727
mkdirp.sync(path.dirname(filePath));
2828
fs.writeFileSync(filePath, JSON.stringify(object));
29-
}
29+
};
3030

31-
export function clearCache() {
31+
exports.clearCache = function() {
3232
return del(CACHE_DIR, {force: true});
33-
}
33+
};
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/* global localStorage */
2-
export function getCache(hash) {
2+
exports.getCache = function(hash) {
33
try {
44
return JSON.parse(localStorage.getItem(hash))
55
} catch (e) {
66
// ignore
77
}
8-
}
8+
};
99

10-
export function setCache(hash, object) {
10+
exports.setCache = function(hash, object) {
1111
localStorage.setItem(hash, JSON.stringify(object));
12-
}
12+
};
1313

14-
export function clearCache() {
14+
exports.clearCache = function() {
1515
return new Promise(resolve => {
1616
localStorage.clear();
1717
resolve();
1818
});
19-
}
19+
};
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {parse} from 'cherow';
2-
import astMatcher from 'ast-matcher';
1+
const {parse} = require('cherow');
2+
const astMatcher = require('ast-matcher');
33

44
function _parser (contents) {
55
// Turn on range to get position info in scope analysis.
@@ -8,7 +8,10 @@ function _parser (contents) {
88
return parse(contents, {ranges: true, loc: true, module: true, next: true});
99
}
1010

11-
if (!astMatcher.__amd_parser_set) {
12-
astMatcher.setParser(_parser);
13-
astMatcher.__amd_parser_set = true;
14-
}
11+
module.exports = function() {
12+
if (!astMatcher.__amd_parser_set) {
13+
astMatcher.setParser(_parser);
14+
astMatcher.__amd_parser_set = true;
15+
}
16+
};
17+

src/index.js renamed to lib/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import trace from './trace';
2-
import {cleanPath, parse, mapId} from 'dumber-module-loader/dist/id-utils';
3-
import defaultPackageFileReader from './package-file-reader/default';
4-
import PackageReader from './package-reader';
5-
import Package from './package';
6-
import stubModule from './stub-module';
7-
import {info, error, warn} from './log';
8-
import {generateHash, stripJsExtension, resolvePackagePath, contentOrFile} from './shared';
9-
import * as cache from './cache/default';
10-
import path from 'path';
11-
import ModulesDone from './modules-done';
12-
import ModulesTodo from './modules-todo';
1+
const trace = require('./trace');
2+
const {cleanPath, parse, mapId} = require('dumber-module-loader/dist/id-utils');
3+
const defaultPackageFileReader = require('./package-file-reader/default');
4+
const PackageReader = require('./package-reader');
5+
const Package = require('./package');
6+
const stubModule = require('./stub-module');
7+
const {info, error, warn} = require('./log');
8+
const {generateHash, stripJsExtension, resolvePackagePath, contentOrFile} = require('./shared');
9+
const cache = require('./cache/default');
10+
const path = require('path');
11+
const ModulesDone = require('./modules-done');
12+
const ModulesTodo = require('./modules-todo');
1313

1414
// Bundler does
1515
// 1. capture: capture units (unit is a file like object plus meta data)
@@ -18,7 +18,7 @@ import ModulesTodo from './modules-todo';
1818

1919
// gulp-dumber or dumberify will then process bundles objects to files
2020

21-
export default class Bundler {
21+
module.exports = class Bundler {
2222
constructor(opts, mock) {
2323
opts = opts || {};
2424
// decoupling for testing
@@ -489,4 +489,4 @@ export default class Bundler {
489489
this._inWatchMode = true;
490490
return bundles;
491491
}
492-
}
492+
};
Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* globals document */
2-
const cssUrlMatcher = /url\s*\(\s*(?!['"]data)([^) ]+)\s*\)/gi;
2+
// Alert: this file will be used in users' app for ext:css plugin,
3+
// use plain ES5 JavaScript Syntax.
4+
var cssUrlMatcher = /url\s*\(\s*(?!['"]data)([^) ]+)\s*\)/gi;
35

46
// copied from aurelia-templating-resources css-resource
57
// This behaves differently from webpack's style-loader.
@@ -8,16 +10,17 @@ const cssUrlMatcher = /url\s*\(\s*(?!['"]data)([^) ]+)\s*\)/gi;
810
// We inject css into a style tag on html head, it means the 'foo/hello.png'
911
// is related to current url (not css url on link tag), or <base> tag in html
1012
// head (which is recommended setup of aurelia-router if not using hash).
11-
export function fixupCSSUrls(address, css) {
13+
function fixupCSSUrls(address, css) {
1214
if (typeof css !== 'string') {
1315
throw new Error(`Failed loading required CSS file: ${address}`);
1416
}
15-
return css.replace(cssUrlMatcher, (match, p1) => {
16-
const quote = p1.charAt(0);
17+
18+
return css.replace(cssUrlMatcher, function(match, p1) {
19+
var quote = p1.charAt(0);
1720
if (quote === '\'' || quote === '"') {
1821
p1 = p1.substr(1, p1.length - 2);
1922
}
20-
const absolutePath = absoluteModuleId(address, p1);
23+
var absolutePath = absoluteModuleId(address, p1);
2124
if (absolutePath === p1) {
2225
return match;
2326
}
@@ -28,30 +31,33 @@ export function fixupCSSUrls(address, css) {
2831
function absoluteModuleId(baseId, moduleId) {
2932
if (moduleId[0] !== '.') return moduleId;
3033

31-
let parts = baseId.split('/');
34+
var parts = baseId.split('/');
3235
parts.pop();
3336

34-
moduleId.split('/').forEach(p => {
35-
if (p === '.') return;
37+
var mParts = moduleId.split('/');
38+
var p;
39+
40+
for (p of mParts) {
41+
if (p === '.') continue;
3642
if (p === '..') {
3743
parts.pop();
38-
return;
44+
continue;
3945
}
4046
parts.push(p);
41-
});
47+
}
4248

4349
return parts.join('/');
4450
}
4551

4652
// copied from aurelia-pal-browser DOM.injectStyles
47-
export function injectCSS(css, id) {
53+
function injectCSS(css, id) {
4854
if (typeof document === 'undefined' || !css) return;
4955
css = fixupCSSUrls(id, css);
5056

5157
if (id) {
52-
let oldStyle = document.getElementById(id);
58+
var oldStyle = document.getElementById(id);
5359
if (oldStyle) {
54-
let isStyleTag = oldStyle.tagName.toLowerCase() === 'style';
60+
var isStyleTag = oldStyle.tagName.toLowerCase() === 'style';
5561

5662
if (isStyleTag) {
5763
oldStyle.innerHTML = css;
@@ -62,7 +68,7 @@ export function injectCSS(css, id) {
6268
}
6369
}
6470

65-
let node = document.createElement('style');
71+
var node = document.createElement('style');
6672
node.innerHTML = css;
6773
node.type = 'text/css';
6874

@@ -74,9 +80,13 @@ export function injectCSS(css, id) {
7480
}
7581

7682
// dumber-module-loader plugin ext:css
77-
export function load(name, req, load) {
78-
req(['text!' + name], text => {
83+
function load(name, req, load) {
84+
req(['text!' + name], function(text) {
7985
injectCSS(text, name);
8086
load(text);
8187
});
82-
}
88+
}
89+
90+
exports.fixupCSSUrls = fixupCSSUrls;
91+
exports.injectCSS = injectCSS;
92+
exports.load = load;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
export function info(message) {
1+
exports.info = function(message) {
22
console.info('[dumber] ' + message);
33
}
44

5-
export function warn(message) {
5+
exports.warn = function(message) {
66
console.warn('[dumber] ' + message);
77
}
88

9-
export function error(message) {
9+
exports.error = function(message) {
1010
console.error('[dumber] ' + message);
1111
}

0 commit comments

Comments
 (0)