stealjs / steal-tools

Build easy. Load fast.
https://stealjs.com/docs/steal-tools.html
MIT License
66 stars 23 forks source link

Build exports wrong cjs format #1139

Closed cherifGsoul closed 4 years ago

cherifGsoul commented 5 years ago

Currently the export for cjs is the same as amd I noticed this in 2 canjs packages, can-log and can-key-tree .

The used steal-tools version "steal-tools": "^2.2.1"

can-log_js_—_can-log
m-mujica commented 4 years ago

This is a shared mutable state bug

My current theory is that there is a shared data structure between each transform and previous code tranforms (AMD -> CJS for example) results are overwritten.

I verified transpile is generating the right output

can-log current build script looks like this:

stealTools.export({
  steal: {
    config: __dirname + "/package.json!npm"
  },
  outputs: {
    "+cjs": {},
    "+amd": {},
    "+global-js": {}
  }
});

When you run it, all built bundles are AMDs (which is the last transform in outputs) but it you change the order of the outputs like this:

stealTools.export({
  steal: {
    config: __dirname + "/package.json!npm"
  },
  outputs: {
    "+amd": {},
    "+global-js": {},
    "+cjs": {},
  }
});

All bundles will be written out as CJS instead (the last transform in the outputs object).

I think the problem might be around here https://github.com/stealjs/steal-tools/blob/019df7f65970e2e515932909c55ca9926c1107eb/lib/build/transform.js#L100 ...

Also, here all transforms share the same graph / data / loader... If I'm not wrong the activeSource object stores each transform and I think it is attached to the loader