Skip to content

Commit

Permalink
Build as ES5, change loader not to use features that would need a hel…
Browse files Browse the repository at this point in the history
…per, and update intern config (#17)
  • Loading branch information
bryanforbes authored Jul 24, 2018
1 parent aa16f4b commit e7f803d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 64 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"lint": "run-p lint:*",
"prettier": "prettier --write \"{src,tests}/**/*.ts\"",
"precommit": "lint-staged",
"release": "run-s lint build \"dojo-release -- {@}\" --",
"release": "run-s lint clean build \"dojo-release -- {@}\" --",
"test": "run-s lint build intern"
},
"bin": {
Expand Down
10 changes: 9 additions & 1 deletion src/intern/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
],

"browser": {
"loader": "./node_modules/@dojo/scripts/intern/loader.js"
"loader": "./node_modules/@dojo/scripts/intern/loader.js",
"reporters": [
{
"name": "html"
},
{
"name": "console"
}
]
},

"node": {
Expand Down
135 changes: 74 additions & 61 deletions src/intern/loader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
declare const shimAmdDependencies: any;

intern.registerLoader(async (options: any) => {
intern.registerLoader((options: any) => {
function assign(object: any, ...args: any[]) {
for (const arg of args) {
Object.keys(arg).forEach((key) => {
object[key] = arg[key];
});
}

return object;
}

const {
packages = [],
map = {},
Expand All @@ -9,66 +19,69 @@ intern.registerLoader(async (options: any) => {
shimPath = 'node_modules/@dojo/framework/shim/util/amd.js'
} = options;

await intern.loadScript(loaderPath);
await intern.loadScript(shimPath);

(require as any).config(
shimAmdDependencies({
baseUrl,
...options,
packages: [
...packages,
{
name: 'cldr-data',
location: 'node_modules/cldr-data'
},
{
name: 'cldrjs',
location: 'node_modules/cldrjs'
},
{
name: 'globalize',
location: 'node_modules/globalize',
main: 'dist/globalize'
},
{
name: 'css-select-umd',
location: 'node_modules/css-select-umd',
main: 'dist/index.js'
},
{
name: 'diff',
location: 'node_modules/diff',
main: 'dist/diff.js'
},
{
name: 'sinon',
location: 'node_modules/sinon/pkg',
main: 'sinon'
}
],
map: {
...map,
globalize: {
cldr: 'cldrjs/dist/cldr',
'cldr/event': 'cldrjs/dist/cldr/event',
'cldr/supplemental': 'cldrjs/dist/cldr/supplemental',
'cldr/unresolved': 'cldrjs/dist/cldr/unresolved'
}
}
return intern
.loadScript(loaderPath)
.then(() => intern.loadScript(shimPath))
.then(() => {
(require as any).config(
shimAmdDependencies(
assign({ baseUrl }, options, {
packages: [
...packages,
{
name: 'cldr-data',
location: 'node_modules/cldr-data'
},
{
name: 'cldrjs',
location: 'node_modules/cldrjs'
},
{
name: 'globalize',
location: 'node_modules/globalize',
main: 'dist/globalize'
},
{
name: 'css-select-umd',
location: 'node_modules/css-select-umd',
main: 'dist/index.js'
},
{
name: 'diff',
location: 'node_modules/diff',
main: 'dist/diff.js'
},
{
name: 'sinon',
location: 'node_modules/sinon/pkg',
main: 'sinon'
}
],
map: assign({}, map, {
globalize: {
cldr: 'cldrjs/dist/cldr',
'cldr/event': 'cldrjs/dist/cldr/event',
'cldr/supplemental': 'cldrjs/dist/cldr/supplemental',
'cldr/unresolved': 'cldrjs/dist/cldr/unresolved'
}
})
})
)
);
})
);

// load @dojo/framework/shim/main to import the ts helpers
await new Promise<void>((resolve) => {
(require as any)(['@dojo/framework/shim/main'], () => {
resolve();
});
});

return (modules: string[]) => {
return new Promise<void>((resolve, reject) => {
(require as any)(modules, () => resolve());
.then(() => {
// load @dojo/framework/shim/main to import the ts helpers
return new Promise<void>((resolve) => {
(require as any)(['@dojo/framework/shim/main'], () => {
resolve();
});
});
})
.then(() => {
return (modules: string[]) => {
return new Promise<void>((resolve, reject) => {
(require as any)(modules, () => resolve());
});
};
});
};
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"downlevelIteration": false,
"importHelpers": false,
"outDir": "dist/cjs",
"target": "es2015"
"target": "es5"
},
"include": [
"./src/**/*.ts",
Expand Down

0 comments on commit e7f803d

Please sign in to comment.