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

compile using babel for compatibility with older versions #96

Merged
merged 22 commits into from Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
296103f
compile using babel for compatibility with older versions
brettz9 Mar 27, 2020
af6a94a
- Update travis for some conditional installs
brettz9 Mar 27, 2020
23bad05
Try with older Rollup plugin versions
brettz9 Mar 27, 2020
148149f
attempt to avoid build on older versions
brettz9 Mar 28, 2020
440dd1a
Babel: Transform `Object.entries`
brettz9 Mar 28, 2020
12c769c
- Attempt using babel/register over esm to utilize babel plugin
brettz9 Mar 28, 2020
bf2688c
Babel: Transform dot-all regex
brettz9 Mar 28, 2020
8cbc7d5
- Travis logic for using older Mocha versions
brettz9 Mar 28, 2020
08420b1
Pass in core-js regexp constructor to tests (so tests can pass)
brettz9 Mar 28, 2020
b78e027
- use babel-register for older Node versions
brettz9 Mar 28, 2020
6334c8c
Revert "Pass in core-js regexp constructor to tests (so tests can pass)"
brettz9 Mar 28, 2020
83cee96
- Switch `engines` to 0.10 minimum
brettz9 Mar 28, 2020
900c8d1
- Undo dotall transformation (only works on literals)
brettz9 Mar 31, 2020
1f093f3
Drop testing for pre-6 Node
brettz9 Apr 4, 2020
3700c83
- Travis: Remove dead code
brettz9 Apr 8, 2020
132ce56
share script in .travis.yml
michaelficarra Apr 8, 2020
0b8640b
remove trailing whitespace
michaelficarra Apr 8, 2020
8c1ec34
Use simpler Node version detection
brettz9 Apr 8, 2020
d8b0377
- Remove unneeded code
brettz9 Apr 8, 2020
60c33c8
- Simplify `npm install` for default Node 10+
brettz9 Apr 8, 2020
a038165
Try dropping `npm install` to rely on default
brettz9 Apr 8, 2020
e6bb4e6
Update .travis.yml
michaelficarra Apr 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .babelrc.json
@@ -0,0 +1,8 @@
{
"presets": [
["@babel/preset-env"]
],
"plugins": [
["transform-es2017-object-entries"]
]
}
3 changes: 3 additions & 0 deletions .editorconfig
Expand Up @@ -16,3 +16,6 @@ indent_size = 2

[*.pegjs]
indent_size = 2

[*.yml]
indent_size = 2
38 changes: 35 additions & 3 deletions .travis.yml
@@ -1,13 +1,45 @@
sudo: false
language: node_js
script:
- npm run build
- npm run test:ci
node_js:
- 6
- 8
- 10
- 12

before_install:
- npm config set depth 0
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
before_script: >
michaelficarra marked this conversation as resolved.
Show resolved Hide resolved
node_version=$(node -v);
michaelficarra marked this conversation as resolved.
Show resolved Hide resolved
if [ ${node_version:3:1} = "." ]; then
echo "Node 10+"
npm install --no-save "eslint@6"
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
npm run build
npm run test:ci
else
if [ ${node_version:1:1} -ge 8 ]; then
echo "Node 8+"
npm install --no-save "eslint@5"
npm run build
npm run test:ci
else
if [ ${node_version:1:1} -ge 6 ]; then
echo "Node 6+"
npm install --no-save "eslint@5" mocha@6.2.2 nyc@14.1.1
npm run test:ci
Copy link
Member

Choose a reason for hiding this comment

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

How are we running the tests without building (npm run build) on this platform?

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see now. By not running the build step, we're testing against the old parser and will fail when we go to add a new feature.

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 don't recall if the build routine works or not (I can try for parity if you like), but it is not needed because the tests are able to run using @babel/register testing against the source instead of dist files.

(I only needed to switch to testing the dist files in the branch where I manually confirmed the old Node builds were still working. But that branch had to undo ESM in the test files and fixtures, avoid other ES6 features, as well as revert to the vulnerable Mocha 3.)

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand. Why would we be able to run "against the source" using @babel/register but not compile? Isn't @babel/register just compiling on the fly and running that?

Copy link
Contributor Author

@brettz9 brettz9 Apr 8, 2020

Choose a reason for hiding this comment

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

On the much older Node versions, @babel/register doesn't work (I switched those to avoid using babel register in favor of just testing against dist), and babel-register doesn't seem to be able to understand the import statements as @babel/register does.

As far as Node 6 that is failing on Travis, yes, @babel/register is compiling on the fly so the babel component should be doable, but it appears that the current @rollup/pluginutils (used by the current versions of @rollup/plugin-commonjs and @rollup/plugin-node-resolve needed in the Rollup config file) is using object spread properties which weren't supported in Node 6. Note that it wouldn't be enough to go back just to an older version here either, as these were previously not in the @rollup scope but were their own packages. But if we go too far back in our toolchain, then certain other features might not have been supported then. And even if we can use the older Rollup deps. across machines, then it may mean adding a version with vulnerabilities.

Is it really critical that the build scripts are confirmed to work on Node 6? These aren't available to work in the npm releases anyways (since the rollup config is not in package.json files and Rollup, etc. are devDeps).

This should really only be needed for those compiling from source on the repo who would presumably have access to more up to date machines. Seems it may be some unnecessary work for little benefit (not to mention adding to the travis build time).

But I can try to see if we can get it to work for Node 6 if it is important.

else
if [ ${node_version:1:1} -ge 4 ]; then
michaelficarra marked this conversation as resolved.
Show resolved Hide resolved
echo "Node 4+"
npm install --no-save "eslint@5" mocha@5 nyc@14.1.1 babel-register
mocha --require core-js/es/regexp/constructor --require chai/register-assert --require babel-register tests
else
echo "Node <4"
npm install --no-save "eslint@5" mocha@3 nyc@14.1.1 babel-register
mocha --require core-js/es/regexp/constructor --require chai/register-assert --require babel-register tests
fi
fi
fi
fi

matrix:
include:
- name: Lint
Expand Down
10 changes: 7 additions & 3 deletions package.json
Expand Up @@ -33,7 +33,7 @@
"build:parser": "rm parser.js && pegjs --cache --format umd -o \"parser.js\" \"grammar.pegjs\"",
"build:browser": "rollup -c",
"build": "npm run build:parser && npm run build:browser",
"mocha": "mocha --require chai/register-assert --require esm tests",
"mocha": "mocha --require chai/register-assert --require @babel/register tests",
"test": "nyc npm run mocha && npm run lint",
"test:ci": "npm run mocha",
"lint": "eslint ."
Expand All @@ -51,22 +51,26 @@
"query"
],
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@babel/register": "^7.9.0",
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-json": "^4.0.2",
"@rollup/plugin-node-resolve": "^7.1.1",
"babel-plugin-transform-es2017-object-entries": "0.0.5",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"esm": "^3.2.25",
"esprima": "~4.0.1",
"mocha": "^7.1.1",
"nyc": "^15.0.0",
"pegjs": "~0.10.0",
"rollup": "^1.32.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-terser": "^5.2.0"
},
"license": "BSD-3-Clause",
"engines": {
"node": ">=8.0"
"node": ">=0.10"
},
"dependencies": {
"estraverse": "^5.0.0"
Expand Down
5 changes: 4 additions & 1 deletion rollup.config.js
Expand Up @@ -4,6 +4,8 @@ import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';

import babel from 'rollup-plugin-babel';

/**
* @external RollupConfig
* @type {PlainObject}
Expand All @@ -30,7 +32,8 @@ function getRollupObject ({ minifying, format = 'umd' } = {}) {
plugins: [
json(),
nodeResolve(),
commonjs()
commonjs(),
babel()
]
};
if (minifying) {
Expand Down
14 changes: 8 additions & 6 deletions tests/queryAttribute.js
Expand Up @@ -177,12 +177,14 @@ describe('Attribute query', function () {
]);
});

it('regexp flag (s)', function () {
const matches = esquery(literal, '[value=/\f.\r/s]');
assert.includeMembers(matches, [
literal.body[0].declarations[0].init
]);
});
if ((/^(?:[89]|\d{2,})\./).test(process.version)) {
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
it('regexp flag (s)', function () {
const matches = esquery(literal, '[value=/\f.\r/s]');
assert.includeMembers(matches, [
literal.body[0].declarations[0].init
]);
});
}

it('regexp flag (m)', function () {
const matches = esquery(literal, '[value=/^\r/m]');
Expand Down