Skip to content

Commit

Permalink
Drop some amount of corejs also the file in git tree
Browse files Browse the repository at this point in the history
Reasons for doing it this way:
1. this lets us easily see what is actually included in the fina core-js
   build by looking at k6-shim.js. The format there is probably going to
   change as it is copied from the core-js repo's shim.js, but the idea
   will stay
2. There is no need to have the shim.min.js in the git tree as it is
   already in lib/rice-box.go. Maybe after the golang embed proposal is
   available we can switch around, but this will likely take more then a
   year before we don't need to support a version of golang without it
3. go generate is awesome, but in this case it has way too many things
   that need to happen which makes it IMO a bad fit. This plus the fact
   that this will not be changed regularly means it is probably better
   this way.
  • Loading branch information
mstoykov committed Dec 15, 2020
1 parent 15e15e5 commit 0e6c0ab
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 36 deletions.
14 changes: 10 additions & 4 deletions js/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,18 @@ func TestNewBundle(t *testing.T) {
}
})
t.Run("CompatibilityMode", func(t *testing.T) {
compatibilityTestSrc := `
module.exports.default = function() {};
if ([[1,2],[3,4]].flatten()[4] == 4) {
throw Error("Array.flatten doesn't work")
}
`

t.Run("Extended/ok/CoreJS", func(t *testing.T) {
rtOpts := lib.RuntimeOptions{
CompatibilityMode: null.StringFrom(lib.CompatibilityModeExtended.String()),
}
_, err := getSimpleBundle(t, "/script.js",
`module.exports.default = function() {}; new Promise(function(resolve, reject){});`, rtOpts)
_, err := getSimpleBundle(t, "/script.js", compatibilityTestSrc, rtOpts)

assert.NoError(t, err)
})
Expand Down Expand Up @@ -156,8 +162,8 @@ func TestNewBundle(t *testing.T) {
// some ES2015 objects polyfilled by core.js are not supported
{
"CoreJS", "base",
`module.exports.default = function() {}; new Promise(function(resolve, reject){});`,
"ReferenceError: Promise is not defined at file:///script.js:1:45(5)",
compatibilityTestSrc,
"TypeError: Object has no member 'flatten' at file:///script.js:3:28(14)",
},
}

Expand Down
19 changes: 19 additions & 0 deletions js/lib/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

sha="a3616d74c0b9b9409d580337e04c32da6e3877e4" # v2.5.1
mkdir -p ./corejs-repo
cd ./corejs-repo
git init
git remote add origin https://github.com/zloirock/core-js.git
git fetch origin --depth=1 "${sha}"
git reset --hard "${sha}"
cp ../k6-shim.js shim.js
cp ../corejs-build.sh corejs-build.sh
docker run --user "$UID:$GID" --rm -ti -v $(pwd):/opt/g --entrypoint /opt/g/corejs-build.sh --workdir /opt/g node
cp custom.min.js ../shim.min.js
cd -
rm -rf corejs-repo
mkdir core-js
mv shim.min.js core-js/shim.min.js
rice embed-go
rm -rf core-js
10 changes: 0 additions & 10 deletions js/lib/core-js/shim.min.js

This file was deleted.

5 changes: 5 additions & 0 deletions js/lib/corejs-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

npm i .
modules="$(cat shim.js | grep ^require | sed "s|require('\./modules/||g" | sed "s/');//g" | tr "\n" ",")"
npm run grunt "build:${modules}" "--library=off" "--path=custom" "uglify"
198 changes: 198 additions & 0 deletions js/lib/k6-shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
//require('./modules/es6.symbol'); // in goja or promises
//require('./modules/es6.object.create');
//require('./modules/es6.object.define-property');
//require('./modules/es6.object.define-properties');
//require('./modules/es6.object.get-own-property-descriptor');
//require('./modules/es6.object.get-prototype-of');
//require('./modules/es6.object.keys');
//require('./modules/es6.object.get-own-property-names');
//require('./modules/es6.object.freeze');
//require('./modules/es6.object.seal');
//require('./modules/es6.object.prevent-extensions');
//require('./modules/es6.object.is-frozen');
//require('./modules/es6.object.is-sealed');
//require('./modules/es6.object.is-extensible');
//require('./modules/es6.object.assign');
//require('./modules/es6.object.is');
//require('./modules/es6.object.set-prototype-of');
//require('./modules/es6.object.to-string');
//require('./modules/es6.function.bind');
//require('./modules/es6.function.name');
//require('./modules/es6.function.has-instance');
//require('./modules/es6.parse-int');
//require('./modules/es6.parse-float');
//require('./modules/es6.number.constructor');
//require('./modules/es6.number.to-fixed');
//require('./modules/es6.number.to-precision');
//require('./modules/es6.number.epsilon');
//require('./modules/es6.number.is-finite');
//require('./modules/es6.number.is-integer');
//require('./modules/es6.number.is-nan');
//require('./modules/es6.number.is-safe-integer');
//require('./modules/es6.number.max-safe-integer');
//require('./modules/es6.number.min-safe-integer');
//require('./modules/es6.number.parse-float');
//require('./modules/es6.number.parse-int');
//require('./modules/es6.math.acosh');
//require('./modules/es6.math.asinh');
//require('./modules/es6.math.atanh');
//require('./modules/es6.math.cbrt');
//require('./modules/es6.math.clz32');
//require('./modules/es6.math.cosh');
//require('./modules/es6.math.expm1');
//require('./modules/es6.math.fround');
//require('./modules/es6.math.hypot');
//require('./modules/es6.math.imul');
//require('./modules/es6.math.log10');
//require('./modules/es6.math.log1p');
//require('./modules/es6.math.log2');
//require('./modules/es6.math.sign');
//require('./modules/es6.math.sinh');
//require('./modules/es6.math.tanh');
//require('./modules/es6.math.trunc');
//require('./modules/es6.string.from-code-point');
//require('./modules/es6.string.raw');
//require('./modules/es6.string.trim');
//require('./modules/es6.string.iterator');
//require('./modules/es6.string.code-point-at');
//require('./modules/es6.string.ends-with');
//require('./modules/es6.string.includes');
//require('./modules/es6.string.repeat');
//require('./modules/es6.string.starts-with');
//require('./modules/es6.string.anchor');
//require('./modules/es6.string.big');
//require('./modules/es6.string.blink');
//require('./modules/es6.string.bold');
//require('./modules/es6.string.fixed');
//require('./modules/es6.string.fontcolor');
//require('./modules/es6.string.fontsize');
//require('./modules/es6.string.italics');
//require('./modules/es6.string.link');
//require('./modules/es6.string.small');
//require('./modules/es6.string.strike');
//require('./modules/es6.string.sub');
//require('./modules/es6.string.sup');
//require('./modules/es6.date.now');
//require('./modules/es6.date.to-json');
//require('./modules/es6.date.to-iso-string');
//require('./modules/es6.date.to-string');
//require('./modules/es6.date.to-primitive');
//require('./modules/es6.array.is-array');
//require('./modules/es6.array.from');
//require('./modules/es6.array.of');
//require('./modules/es6.array.join');
//require('./modules/es6.array.slice');
//require('./modules/es6.array.sort');
//require('./modules/es6.array.for-each');
//require('./modules/es6.array.map');
//require('./modules/es6.array.filter');
//require('./modules/es6.array.some');
//require('./modules/es6.array.every');
//require('./modules/es6.array.reduce');
//require('./modules/es6.array.reduce-right');
//require('./modules/es6.array.index-of');
//require('./modules/es6.array.last-index-of');
//require('./modules/es6.array.copy-within');
//require('./modules/es6.array.fill');
//require('./modules/es6.array.find');
//require('./modules/es6.array.find-index');
//require('./modules/es6.array.species');
//require('./modules/es6.array.iterator');
//require('./modules/es6.regexp.constructor');
//require('./modules/es6.regexp.to-string');
//require('./modules/es6.regexp.flags');
//require('./modules/es6.regexp.match');
//require('./modules/es6.regexp.replace');
//require('./modules/es6.regexp.search');
//require('./modules/es6.regexp.split');
//require('./modules/es6.promise');
//require('./modules/es6.map');
//require('./modules/es6.set');
//require('./modules/es6.weak-map');
//require('./modules/es6.weak-set');
//require('./modules/es6.typed.array-buffer');
//require('./modules/es6.typed.data-view');
//require('./modules/es6.typed.int8-array');
//require('./modules/es6.typed.uint8-array');
//require('./modules/es6.typed.uint8-clamped-array');
//require('./modules/es6.typed.int16-array');
//require('./modules/es6.typed.uint16-array');
//require('./modules/es6.typed.int32-array');
//require('./modules/es6.typed.uint32-array');
//require('./modules/es6.typed.float32-array');
//require('./modules/es6.typed.float64-array');
//require('./modules/es6.reflect.apply');
//require('./modules/es6.reflect.construct');
//require('./modules/es6.reflect.define-property');
//require('./modules/es6.reflect.delete-property');
//require('./modules/es6.reflect.enumerate');
//require('./modules/es6.reflect.get');
//require('./modules/es6.reflect.get-own-property-descriptor');
//require('./modules/es6.reflect.get-prototype-of');
//require('./modules/es6.reflect.has');
//require('./modules/es6.reflect.is-extensible');
//require('./modules/es6.reflect.own-keys');
//require('./modules/es6.reflect.prevent-extensions');
//require('./modules/es6.reflect.set');
//require('./modules/es6.reflect.set-prototype-of');
//require('./modules/es7.array.includes'); // in goja
require('./modules/es7.array.flat-map');
// this is now called flat, so maybe drop it https://github.com/tc39/proposal-flatMap
require('./modules/es7.array.flatten');
//require('./modules/es7.string.at'); // it is in es2020 but is with completely different semantics
//require('./modules/es7.string.pad-start'); // in goja
//require('./modules/es7.string.pad-end'); // in goja
require('./modules/es7.string.trim-left');
require('./modules/es7.string.trim-right');
require('./modules/es7.string.match-all');
//require('./modules/es7.symbol.async-iterator'); // async
//require('./modules/es7.symbol.observable');
require('./modules/es7.object.get-own-property-descriptors');
require('./modules/es7.object.values');
require('./modules/es7.object.entries');
require('./modules/es7.object.define-getter');
require('./modules/es7.object.define-setter');
require('./modules/es7.object.lookup-getter');
require('./modules/es7.object.lookup-setter');
// require('./modules/es7.map.to-json'); // not actually in the standard
//require('./modules/es7.set.to-json');
//require('./modules/es7.map.of');
//require('./modules/es7.set.of');
//require('./modules/es7.weak-map.of');
//require('./modules/es7.weak-set.of');
//require('./modules/es7.map.from');
//require('./modules/es7.set.from');
//require('./modules/es7.weak-map.from');
//require('./modules/es7.weak-set.from');
//require('es7.global'); // is now globalThis, goja has globasl
//require('es7.system.global'); // dropped .. I think
//require('es7.error.is-error'); // dropped
//require('./modules/es7.math.clamp'); // not actually in the standard
//require('./modules/es7.math.deg-per-rad');
//require('./modules/es7.math.degrees');
//require('./modules/es7.math.fscale');
//require('./modules/es7.math.iaddh');
//require('./modules/es7.math.isubh');
//require('./modules/es7.math.imulh');
//require('./modules/es7.math.rad-per-deg');
//require('./modules/es7.math.radians');
//require('./modules/es7.math.scale');
//require('./modules/es7.math.umulh');
//require('./modules/es7.math.signbit');
//require('./modules/es7.promise.finally'); // promises
//require('./modules/es7.promise.try');
require('./modules/es7.reflect.define-metadata');
require('./modules/es7.reflect.delete-metadata');
require('./modules/es7.reflect.get-metadata');
require('./modules/es7.reflect.get-metadata-keys');
require('./modules/es7.reflect.get-own-metadata');
require('./modules/es7.reflect.get-own-metadata-keys');
require('./modules/es7.reflect.has-metadata');
require('./modules/es7.reflect.has-own-metadata');
require('./modules/es7.reflect.metadata');
//require('./modules/es7.asap'); // promises
//require('./modules/es7.observable');
//require('./modules/web.timers'); // web stuff
//require('./modules/web.immediate');
//require('./modules/web.dom.iterable');
// module.exports = require('./modules/_core');
2 changes: 0 additions & 2 deletions js/lib/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*
*/

//go:generate rice embed-go

package lib

import (
Expand Down
13 changes: 8 additions & 5 deletions js/lib/rice-box.go

Large diffs are not rendered by default.

Loading

0 comments on commit 0e6c0ab

Please sign in to comment.