mirror of
https://github.com/systemjs/systemjs.git
synced 2026-02-01 15:59:54 +00:00
fix: build source maps (#2416)
This commit is contained in:
parent
1c79bfcd9f
commit
8bae641d84
@ -5,7 +5,7 @@ default-task = 'build'
|
||||
extensions = [
|
||||
'chomp@0.1:npm',
|
||||
'chomp@0.1:footprint',
|
||||
'chomp@0.1:terser',
|
||||
'./terser.js',
|
||||
'chomp@0.1:rollup',
|
||||
'chomp@0.1:ncc'
|
||||
]
|
||||
|
||||
2
dist/extras/amd.min.js
vendored
2
dist/extras/amd.min.js
vendored
@ -1,2 +1,2 @@
|
||||
!function(){function e(e,r){return(r||"")+" (SystemJS Error#"+e+" https://github.com/systemjs/systemjs/blob/main/docs/errors.md#"+e+")"}!function(r){function t(){throw Error(e(5,"AMD require not supported."))}var n=["require","exports","module"];r.define=function(r,o,s){var i,u,f="string"==typeof r,l=f?r:null,a=f?o:r,d=f?s:o;if(Array.isArray(a))i=a,u=d;else if("object"==typeof a)i=[],u=function(){return a};else{if("function"!=typeof a)throw Error(e(9,"Invalid call to AMD define()"));i=n,u=a}var c=function(e,r){function n(e){u.push((function(r){i[e]=r.__useDefault?r.default:r}))}for(var o={},s={exports:o},i=[],u=[],f=0,l=0;l<e.length;l++){var a=e[l],d=u.length;"require"===a?(i[l]=t,f++):"module"===a?(i[l]=s,f++):"exports"===a?(i[l]=o,f++):n(l),f&&(e[d]=a)}f&&(e.length-=f);var c=r;return[e,function(e){return e({default:o,__useDefault:!0}),{setters:u,execute:function(){var r=c.apply(o,i);void 0!==r&&(s.exports=r),e(s.exports),e("default",s.exports)}}}]}(i,u);f?(System.registerRegistry?(System.registerRegistry[l]=c,System.register(l,c[0],c[1])):console.warn(e("W6","Include named-register.js for full named define support")),System.register(c[0],c[1])):System.register(c[0],c[1])},r.define.amd={}}("undefined"!=typeof self?self:global)}();
|
||||
//# sourceMappingURL=##.min.js.map
|
||||
//# sourceMappingURL=amd.min.js
|
||||
2
dist/extras/dynamic-import-maps.min.js
vendored
2
dist/extras/dynamic-import-maps.min.js
vendored
@ -1,2 +1,2 @@
|
||||
new MutationObserver((function(e){for(var t=0;t<e.length;t++){var r=e[t];if("childList"===r.type)for(var a=0;a<r.addedNodes.length;a++){var s=r.addedNodes[a];if("SCRIPT"===s.tagName&&"systemjs-importmap"===s.type&&!s.sp){System.prepareImport(!0);break}}}})).observe(document,{childList:!0,subtree:!0});
|
||||
//# sourceMappingURL=##.min.js.map
|
||||
//# sourceMappingURL=dynamic-import-maps.min.js
|
||||
2
dist/extras/global.min.js
vendored
2
dist/extras/global.min.js
vendored
@ -1,2 +1,2 @@
|
||||
!function(t){function n(n){return!t.hasOwnProperty(n)||!isNaN(n)&&n<t.length||c&&t[n]&&"undefined"!=typeof window&&t[n].parent===window}var r,e,i,o=t.System.constructor.prototype,u=o.import;o.import=function(o,f){return function(){for(var o in r=e=void 0,t)n(o)||(r?e||(e=o):r=o,i=o)}(),u.call(this,o,f)};var f=[[],function(){return{}}],a=o.getRegister;o.getRegister=function(){var o=a.call(this);if(o)return o;var u,c=function(o){var u,f,a=0;for(var c in t)if(!n(c)){if(0===a&&c!==r||1===a&&c!==e)return c;u?(i=c,f=o&&f||c):u=c===i,a++}return f}(this.firstGlobalProp);if(!c)return f;try{u=t[c]}catch(s){return f}return[[],function(t){return{execute:function(){t(u),t({default:u,__useDefault:!0})}}}]};var c="undefined"!=typeof navigator&&-1!==navigator.userAgent.indexOf("Trident")}("undefined"!=typeof self?self:global);
|
||||
//# sourceMappingURL=##.min.js.map
|
||||
//# sourceMappingURL=global.min.js
|
||||
2
dist/extras/module-types.min.js
vendored
2
dist/extras/module-types.min.js
vendored
@ -1,2 +1,2 @@
|
||||
!function(){function e(e,t){if(-1!==e.indexOf("\\")&&(e=e.replace(i,"/")),"/"===e[0]&&"/"===e[1])return t.slice(0,t.indexOf(":")+1)+e;if("."===e[0]&&("/"===e[1]||"."===e[1]&&("/"===e[2]||2===e.length&&(e+="/"))||1===e.length&&(e+="/"))||"/"===e[0]){var n,s=t.slice(0,t.indexOf(":")+1);if(n="/"===t[s.length+1]?"file:"!==s?(n=t.slice(s.length+2)).slice(n.indexOf("/")+1):t.slice(8):t.slice(s.length+("/"===t[s.length])),"/"===e[0])return t.slice(0,t.length-n.length-1)+e;for(var r=n.slice(0,n.lastIndexOf("/")+1)+e,l=[],o=-1,c=0;c<r.length;c++)-1!==o?"/"===r[c]&&(l.push(r.slice(o,c+1)),o=-1):"."===r[c]?"."!==r[c+1]||"/"!==r[c+2]&&c+2!==r.length?"/"===r[c+1]||c+1===r.length?c+=1:o=c:(l.pop(),c+=2):o=c;return-1!==o&&l.push(r.slice(o)),t.slice(0,t.length-n.length)+l.join("")}}var t;if("undefined"!=typeof document){var n=document.querySelector("base[href]");n&&(t=n.href)}if(!t&&"undefined"!=typeof location){var s=(t=location.href.split("#")[0].split("?")[0]).lastIndexOf("/");-1!==s&&(t=t.slice(0,s+1))}var i=/\\/g;!function(t){var n=t.System.constructor.prototype,s=/^[^#?]+\.(css|html|json|wasm)([?#].*)?$/;n.shouldFetch=function(e){return s.test(e)};var i=/^application\/json(;|$)/,r=/^text\/css(;|$)/,l=/^application\/wasm(;|$)/,o=n.fetch;n.fetch=function(n,s){return o(n,s).then((function(o){if(s.passThrough)return o;if(!o.ok)return o;var c=o.headers.get("content-type");return i.test(c)?o.json().then((function(e){return new Response(new Blob(['System.register([],function(e){return{execute:function(){e("default",'+JSON.stringify(e)+")}}})"],{type:"application/javascript"}))})):r.test(c)?o.text().then((function(t){return t=t.replace(/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g,(function(t,s,i,r){return"url("+s+(e(l=i||r,o=n)||(-1!==l.indexOf(":")?l:e("./"+l,o)))+s+")";var l,o})),new Response(new Blob(["System.register([],function(e){return{execute:function(){var s=new CSSStyleSheet();s.replaceSync("+JSON.stringify(t)+');e("default",s)}}})'],{type:"application/javascript"}))})):l.test(c)?(WebAssembly.compileStreaming?WebAssembly.compileStreaming(o):o.arrayBuffer().then(WebAssembly.compile)).then((function(e){t.System.wasmModules||(t.System.wasmModules=Object.create(null)),t.System.wasmModules[n]=e;var s=[],i=[];return WebAssembly.Module.imports&&WebAssembly.Module.imports(e).forEach((function(e){var t=JSON.stringify(e.module);-1===s.indexOf(t)&&(s.push(t),i.push("function(m){i["+t+"]=m}"))})),new Response(new Blob(["System.register(["+s.join(",")+"],function(e){var i={};return{setters:["+i.join(",")+"],execute:function(){return WebAssembly.instantiate(System.wasmModules["+JSON.stringify(n)+"],i).then(function(m){e(m.exports)})}}})"],{type:"application/javascript"}))})):o}))}}("undefined"!=typeof self?self:global)}();
|
||||
//# sourceMappingURL=##.min.js.map
|
||||
//# sourceMappingURL=module-types.min.js
|
||||
2
dist/extras/named-exports.min.js
vendored
2
dist/extras/named-exports.min.js
vendored
@ -1,2 +1,2 @@
|
||||
!function(t){var e,r=t.System.constructor.prototype,n=r.register;r.register=function(t,r,f){e="string"==typeof t?f:r,n.apply(this,arguments)};var f=r.getRegister;r.getRegister=function(){var t=f.call(this);if(!t||t[1]===e||0===t[1].length)return t;var r=t[1];return t[1]=function(t,e){var n,f=!1,u=r.call(this,(function(e,r){"object"==typeof e&&e&&e.__useDefault?(n=e.default,f=!0):"default"===e?n=r:"__useDefault"===e&&(f=!0),t(e,r)}),e),i=u.execute;return i&&(u.execute=function(){if(i.call(this),f)for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&"default"!==e&&t(e,n[e])}),u},t}}("undefined"!=typeof self?self:global);
|
||||
//# sourceMappingURL=##.min.js.map
|
||||
//# sourceMappingURL=named-exports.min.js
|
||||
2
dist/extras/named-register.min.js
vendored
2
dist/extras/named-register.min.js
vendored
@ -1,2 +1,2 @@
|
||||
!function(t){function e(t){t.registerRegistry=Object.create(null),t.namedRegisterAliases=Object.create(null)}var r=t.System;e(r);var i,s,n=r.constructor.prototype,l=r.constructor,a=function(){l.call(this),e(this)};a.prototype=n,r.constructor=a;var o=n.register;n.register=function(t,e,r){if("string"!=typeof t)return o.apply(this,arguments);var n=[e,r];return this.registerRegistry[t]=n,i||(i=n,s=t),Promise.resolve().then((function(){i=null,s=null})),o.call(this,e,r)};var c=n.resolve;n.resolve=function(t,e){try{return c.call(this,t,e)}catch(r){if(t in this.registerRegistry)return this.namedRegisterAliases[t]||t;throw r}};var u=n.instantiate;n.instantiate=function(t,e){var r=this.registerRegistry[t];return r?(this.registerRegistry[t]=null,r):u.call(this,t,e)};var g=n.getRegister;n.getRegister=function(t){var e=g.call(this,t);s&&t&&(this.namedRegisterAliases[s]=t);var r=i||e;return i=null,s=null,r}}("undefined"!=typeof self?self:global);
|
||||
//# sourceMappingURL=##.min.js.map
|
||||
//# sourceMappingURL=named-register.min.js
|
||||
2
dist/extras/transform.min.js
vendored
2
dist/extras/transform.min.js
vendored
@ -1,2 +1,2 @@
|
||||
!function(t){var r=t.System.constructor.prototype,e=r.instantiate;r.instantiate=function(t,r){if(".wasm"===t.slice(-5))return e.call(this,t,r);var n=this;return fetch(t,{credentials:"same-origin"}).then((function(t){if(!t.ok)throw Error(("Fetch error: "+t.status+" "+t.statusText+(r?" loading from "+r:"")||"")+" (SystemJS Error#"+7+" https://github.com/systemjs/systemjs/blob/main/docs/errors.md#7)");return t.text()})).then((function(r){return n.transform.call(this,t,r)})).then((function(r){return(0,eval)(r+"\n//# sourceURL="+t),n.getRegister(t)}))},r.transform=function(t,r){return r}}("undefined"!=typeof self?self:global);
|
||||
//# sourceMappingURL=##.min.js.map
|
||||
//# sourceMappingURL=transform.min.js
|
||||
2
dist/extras/use-default.min.js
vendored
2
dist/extras/use-default.min.js
vendored
@ -1,2 +1,2 @@
|
||||
!function(t){var e=t.System.constructor.prototype,n=e.import;e.import=function(){return n.apply(this,arguments).then((function(t){return t.__useDefault?t.default:t}))}}("undefined"!=typeof self?self:global);
|
||||
//# sourceMappingURL=##.min.js.map
|
||||
//# sourceMappingURL=use-default.min.js
|
||||
40
terser.js
Normal file
40
terser.js
Normal file
@ -0,0 +1,40 @@
|
||||
Chomp.addExtension('chomp@0.1:npm');
|
||||
|
||||
Chomp.registerTemplate('terser', function (task) {
|
||||
if (task.engine || task.run)
|
||||
throw new Error('"engine", "run" not configurable for Terser template.');
|
||||
|
||||
const opts = task.templateOptions;
|
||||
const preamble = opts.output?.preamble;
|
||||
const pjsonVersion = typeof preamble === 'string' && preamble.includes('#PJSON_VERSION');
|
||||
const { autoInstall } = opts;
|
||||
const targetName = task.targets[0].split('/').pop();
|
||||
if (opts.sourceMap === true)
|
||||
opts.sourceMap = { filename: targetName, url: '$TARGET', includeSources: true };
|
||||
const optionsStr = JSON.stringify(opts, null, 2).replace(/\n/g, '\n ').replace('"$TARGET"', 'basename(process.env.TARGET)');
|
||||
|
||||
return [{
|
||||
name: task.name,
|
||||
targets: task.targets,
|
||||
deps: [...task.deps, ...pjsonVersion ? ['package.json'] : [], ...ENV.CHOMP_EJECT ? ['npm:install'] : ['node_modules/terser']],
|
||||
engine: 'node',
|
||||
run: ` import { readFileSync, writeFileSync } from 'fs';
|
||||
import { basename } from 'path';
|
||||
import { minify } from 'terser';
|
||||
|
||||
${pjsonVersion ? ` const pjson = JSON.parse(readFileSync('package.json', 'utf8'));` : ''}
|
||||
const { code, map } = await minify({ [basename(process.env.DEP)]: readFileSync(process.env.DEP, 'utf8') }, ${
|
||||
pjsonVersion ? optionsStr.replace('"preamble": ' + JSON.stringify(preamble), '"preamble": `' + preamble.replace(/(\`|\${)/, '\\$1').replace('#PJSON_VERSION', '${pjson.version}') + '`') : optionsStr
|
||||
});
|
||||
|
||||
writeFileSync(process.env.TARGET, code);
|
||||
${opts.sourceMap ? ' writeFileSync(\`\${process.env.TARGET}.map\`, map);\n' : ''}`
|
||||
}, ...ENV.CHOMP_EJECT ? [] : [{
|
||||
template: 'npm',
|
||||
templateOptions: {
|
||||
autoInstall,
|
||||
packages: ['terser@5'],
|
||||
dev: true
|
||||
}
|
||||
}]];
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user