Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop some amount of corejs also the file in git tree #1772

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Copy link
Contributor

@imiric imiric Dec 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would never fail, no? It would always be undefined, even if flatten() works, unless you meant [3] === 4. Ah, nevermind, the index doesn't actually matter. :)

But this would be better checked with if (typeof Array.prototype.flatten !== 'function') ....

Also maybe we should use a different object to test this, since flatten was renamed to flat in corejs v3, and it would avoid us having to update this when we update to v3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this would be better checked with if (typeof Array.prototype.flatten !== 'function') ....

We should have both of these. First check if it's actually a function, and fast fail if it's no, then whether the behavior is at least somewhat along the lines of what one could expect.

Also maybe we should use a different object to test this, since flatten was renamed to flat in corejs v3, and it would avoid us having to update this when we update to v3.

Array.prototype.flat is the actual name according to the specification. We should probably use that name as well.

}
`

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
mstoykov marked this conversation as resolved.
Show resolved Hide resolved
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 .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failing for me when I run build.sh. grunt fails to install because of:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/grunt
npm ERR!   dev grunt@"1.0.x" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer grunt@"~0.4" from [email protected]
npm ERR! node_modules/grunt-livescript
npm ERR!   dev grunt-livescript@"0.6.x" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

npm i --force works, but maybe there's a better workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm ... that seems to be because I don't specify a version for node and it works with mine (14.x something) while it doesn't work with 15.4.0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

14.x is still the LTS, so as long as it works with that, I wouldn't bother. Usually, current, contains weird kinks until it reaches lts.

modules="$(cat shim.js | grep ^require | sed "s|require('\./modules/||g" | sed "s/');//g" | tr "\n" ",")"
Copy link
Contributor

@imiric imiric Dec 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, you could simplify this to:

Suggested change
modules="$(cat shim.js | grep ^require | sed "s|require('\./modules/||g" | sed "s/');//g" | tr "\n" ",")"
modules="$(sed -n "s:^require('\./modules/\(.*\)');:\1:p" shim.js | paste -sd',')"

Also see useless use of cat ;)

Errm I messed up the quoting there so you'll need to escape it properly, but the command should work. Nevermind, it works fine with /bin/sh, just tested it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not going to this for now, as if we remove more from the shim.js or change its format, I will need to redo it.
For example, if we are finally left with 5-10 items I am probably just going to hard them inside the script instead of having a file with an explanation on what is what and why ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, though I don't see a reason why not to simplify this anyway.

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');
simskij marked this conversation as resolved.
Show resolved Hide resolved
//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