Skip to content

Commit

Permalink
chore(codegen): enable minification on output
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Nov 12, 2023
1 parent 8ab4b91 commit 0792123
Show file tree
Hide file tree
Showing 75 changed files with 126 additions and 1,468 deletions.
18 changes: 12 additions & 6 deletions create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import colors from 'picocolors';
import { dequal } from 'dequal';
import { fileExists, compareAndWriteFile } from '@nolyfill/internal';
import { transform } from '@swc/core';
import type { Options as SwcOptions } from '@swc/core';

import type { PackageJson } from 'type-fest';

Expand Down Expand Up @@ -191,22 +192,27 @@ module.exports = exports.default;
`;

const defaultExportInterop = `
if ((typeof exports.default === 'object' && exports.default !== null) || typeof exports.default === 'function') {
Object.assign(exports.default, exports);
}
((typeof exports.default === 'object' && exports.default !== null) || typeof exports.default === 'function') && Object.assign(exports.default,exports);
module.exports = exports.default;
`;

const sharedSwcOption = {
const sharedSwcOption: SwcOptions = {
isModule: true,
jsc: {
parser: {
syntax: 'typescript'
},
target: 'es2018'
target: 'es2018',
minify: {
compress: true,
mangle: true,
module: true,
sourceMap: false
}
},
minify: true,
module: { type: 'commonjs' }
} as const;
};

async function createEsShimLikePackage(
packageName: string,
Expand Down
29 changes: 2 additions & 27 deletions packages/generated/array-buffer-byte-length/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 1 addition & 13 deletions packages/generated/array-includes/entry.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _shared = require("@nolyfill/shared");
const _default = (0, _shared.defineEsShim)(Array.prototype.includes);

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return r}});const e=require("@nolyfill/shared"),r=(0,e.defineEsShim)(Array.prototype.includes);
Object.assign(exports.default, exports);
module.exports = exports.default;
14 changes: 1 addition & 13 deletions packages/generated/array.from/entry.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _shared = require("@nolyfill/shared");
const _default = (0, _shared.defineEsShim)(Array.from, true);

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return r}});const e=require("@nolyfill/shared"),r=(0,e.defineEsShim)(Array.from,!0);
Object.assign(exports.default, exports);
module.exports = exports.default;
20 changes: 1 addition & 19 deletions packages/generated/array.prototype.at/entry.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _shared = require("@nolyfill/shared");
const implementation = Array.prototype.at || function at(n) {
n = Math.trunc(n) || 0;
if (n < 0) n += this.length;
if (n < 0 || n >= this.length) return;
return this[n];
};
const _default = (0, _shared.defineEsShim)(implementation);

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return r}});const e=require("@nolyfill/shared"),t=Array.prototype.at||function(e){if((e=Math.trunc(e)||0)<0&&(e+=this.length),!(e<0)&&!(e>=this.length))return this[e]},r=(0,e.defineEsShim)(t);
Object.assign(exports.default, exports);
module.exports = exports.default;
14 changes: 1 addition & 13 deletions packages/generated/array.prototype.find/entry.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _shared = require("@nolyfill/shared");
const _default = (0, _shared.defineEsShim)(Array.prototype.find);

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return r}});const e=require("@nolyfill/shared"),r=(0,e.defineEsShim)(Array.prototype.find);
Object.assign(exports.default, exports);
module.exports = exports.default;
22 changes: 1 addition & 21 deletions packages/generated/array.prototype.findlast/entry.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _shared = require("@nolyfill/shared");
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- polyfill
const implementation = Array.prototype.findLast || function findLast(callback, thisArg) {
for(let i = this.length - 1; i >= 0; i--){
const value = this[i];
if (callback.call(thisArg, value, i, this)) return value;
}
return undefined;
};
const _default = (0, _shared.defineEsShim)(implementation);

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return r}});const e=require("@nolyfill/shared"),t=Array.prototype.findLast||function(e,t){for(let r=this.length-1;r>=0;r--){let i=this[r];if(e.call(t,i,r,this))return i}},r=(0,e.defineEsShim)(t);
Object.assign(exports.default, exports);
module.exports = exports.default;
20 changes: 1 addition & 19 deletions packages/generated/array.prototype.findlastindex/entry.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _shared = require("@nolyfill/shared");
const implementation = Array.prototype.findLastIndex || function findLastIndex(callback, thisArg) {
for(let i = this.length - 1; i >= 0; i--){
if (callback.call(thisArg, this[i], i, this)) return i;
}
return -1;
};
const _default = (0, _shared.defineEsShim)(implementation);

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return r}});const e=require("@nolyfill/shared"),t=Array.prototype.findLastIndex||function(e,t){for(let r=this.length-1;r>=0;r--)if(e.call(t,this[r],r,this))return r;return -1},r=(0,e.defineEsShim)(t);
Object.assign(exports.default, exports);
module.exports = exports.default;
14 changes: 1 addition & 13 deletions packages/generated/array.prototype.flat/entry.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _shared = require("@nolyfill/shared");
const _default = (0, _shared.defineEsShim)(Array.prototype.flat);

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return r}});const e=require("@nolyfill/shared"),r=(0,e.defineEsShim)(Array.prototype.flat);
Object.assign(exports.default, exports);
module.exports = exports.default;
14 changes: 1 addition & 13 deletions packages/generated/array.prototype.flatmap/entry.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _shared = require("@nolyfill/shared");
const _default = (0, _shared.defineEsShim)(Array.prototype.flatMap);

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return r}});const e=require("@nolyfill/shared"),r=(0,e.defineEsShim)(Array.prototype.flatMap);
Object.assign(exports.default, exports);
module.exports = exports.default;
14 changes: 1 addition & 13 deletions packages/generated/array.prototype.reduce/entry.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _shared = require("@nolyfill/shared");
const _default = (0, _shared.defineEsShim)(Array.prototype.reduce);

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return r}});const e=require("@nolyfill/shared"),r=(0,e.defineEsShim)(Array.prototype.reduce);
Object.assign(exports.default, exports);
module.exports = exports.default;
24 changes: 1 addition & 23 deletions packages/generated/array.prototype.tosorted/entry.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _shared = require("@nolyfill/shared");
const implementation = Array.prototype.toSorted || function toSorted(compareFn) {
const o = Object(this);
const l = Number(o.length);
const a = new Array(l);
for(let i = 0; i < l; i++){
a[i] = o[i];
}
Array.prototype.sort.call(a, compareFn);
return a;
};
const _default = (0, _shared.defineEsShim)(implementation);

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return t}});const e=require("@nolyfill/shared"),r=Array.prototype.toSorted||function(e){let r=Object(this),t=Number(r.length),o=Array(t);for(let e=0;e<t;e++)o[e]=r[e];return Array.prototype.sort.call(o,e),o},t=(0,e.defineEsShim)(r);
Object.assign(exports.default, exports);
module.exports = exports.default;
14 changes: 1 addition & 13 deletions packages/generated/arraybuffer.prototype.slice/entry.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _shared = require("@nolyfill/shared");
const _default = (0, _shared.defineEsShim)(ArrayBuffer.prototype.slice);

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return r}});const e=require("@nolyfill/shared"),r=(0,e.defineEsShim)(ArrayBuffer.prototype.slice);
Object.assign(exports.default, exports);
module.exports = exports.default;
23 changes: 2 additions & 21 deletions packages/generated/asynciterator.prototype/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 2 additions & 27 deletions packages/generated/available-typed-arrays/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 2 additions & 17 deletions packages/generated/deep-equal/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const _dequal = require("dequal");
const deepEqual = (a, b)=>(0, _dequal.dequal)(a, b);
const _default = deepEqual;

if ((typeof exports.default === 'object' && exports.default !== null) || typeof exports.default === 'function') {
Object.assign(exports.default, exports);
}
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return t}});const e=require("dequal"),t=(t,r)=>(0,e.dequal)(t,r);
((typeof exports.default === 'object' && exports.default !== null) || typeof exports.default === 'function') && Object.assign(exports.default,exports);
module.exports = exports.default;
17 changes: 2 additions & 15 deletions packages/generated/define-properties/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _shared.defineProperties;
}
});
const _shared = require("@nolyfill/shared");

if ((typeof exports.default === 'object' && exports.default !== null) || typeof exports.default === 'function') {
Object.assign(exports.default, exports);
}
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"default",{enumerable:!0,get:function(){return e.defineProperties}});const e=require("@nolyfill/shared");
((typeof exports.default === 'object' && exports.default !== null) || typeof exports.default === 'function') && Object.assign(exports.default,exports);
module.exports = exports.default;
Loading

0 comments on commit 0792123

Please sign in to comment.