netcreateorg / netcreate-itest

Developing the 2.0 version of NetCreate
https://github.com/netcreateorg/netcreate-2018
Other
0 stars 0 forks source link

Add Object Spread (ES2018) Syntax to Brunch Babel Config #219

Closed dsriseah closed 1 month ago

dsriseah commented 1 month ago

The Problem

You can't use object spread in NetCreate, eg const clone = { ...original, id: 1} or something like that. This PR modifies the babel config used by brunch to enable it.

Testing

After pulling the branch, try replacing any Object.assign code with the equivalent spread syntax. E.g. change const bar = Object.assign({}, foo, {name:'foo2') to const foo = { ...foo, name:'foo2' }

See if NetCreate handles this correctly


TECHNICAL BACKGROUND

In current NetCreate 2.0, we are maintaining the 2017-era brunch build system, which is unaware of features that occurred afterwards. The difficulties are summarized in the aborted #80 "Module Architecture Stage 2".

We are dependent on the pre-7.0 version of Babel because Brunch 2.10 uses the old Babel as a dependency. It appears to be around version 6.7, though we can go right up to 6.26.3 (the last pre-7.0 Babel). This means we use the old babel repo for our reference, as syntax changed significantly in 7.

THE FIX

Install the old version of babel object spread, not the newer one.

npm i -D babel-plugin-transform-object-rest-spread

Then update the brunch-config.js file by adding this line to the plugins/babel field.

plugins: ['transform-object-rest-spread']
benloh commented 1 month ago

Confirmed this works using dev-bl/functional working branch. Thank you!