WebReflection Ltd
webreflection / ascjs Goto Github PK
View Code? Open in Web Editor NEWES2015 to CommonJS import/export transformer
License: ISC License
ES2015 to CommonJS import/export transformer
License: ISC License
Use case, you have ES Modules files in src
, but there you also have src/cli.js
which is actual real cjs file with shebang.
I propose to skip such files that don't have import/export
s, so just copy them without transforming them.
Say you have this src/cli.js
#!/usr/bin/env node
'use strict';
const proc = require('process');
// ... cli code
it gets transformed to invalid bin file
'use strict';
#!/usr/bin/env node
'use strict';
const proc = require('process');
// ... rest
The current behaviour leads to duplicated 'use strict'
line when the source already contains it.
ascjs --ignore=main.mjs src/ lib/
| /packages/asciidoctor/project/node_modules/ascjs/bin.js:15
| .map(file => path.resolve(__dirname, file))
| ^
|
| ReferenceError: path is not defined
| at ignore.push.apply.arg.slice.replace.split.map.file packages/asciidoctor/(project/node_modules/ascjs/bin.js:15:29)
| at Array.map (<anonymous>)
| at options.forEach.arg packages/asciidoctor/(project/node_modules/ascjs/bin.js:15:12)
| at Array.forEach (<anonymous>)
| at Object.<anonymous> packages/asciidoctor/(project/node_modules/ascjs/bin.js:10:9)
| at Module._compile (module.js:653:30)
| at Object.Module._extensions..js (module.js:664:10)
| at Module.load (module.js:566:32)
| at tryModuleLoad (module.js:506:12)
| at Function.Module._load (module.js:498:3)
If import.meta
is found in the wild the equivalent CJS will likely break.
This module should ensure that import.meta
is translated as {url: __filename}
, taking into account Windows shenanigans with paths.
The following lines are not equivalent because namespace objects do not contain default exports.
import * as tmp from 'other';
const tmp = require('other');
It would be possible to add some conditional handling for the case where 'other' is found to be an ES module. Let me know if you are interested in PRs for this kind of thing.
Problem: when I develop an esm module back-ported to cjs with ascjs, I sometimes link the module to a local consumer module that is running in cjs mode. When I modify the esm module, I forget to re-compile the cjs version and end up pulling out my hair when it doesn't change things like I expect, and then eventually remember to recompile. (Has happened 2-3 time now 😅)
Possible solution: add a watch flag to ascjs. This way, when working on the esm portion, any file changes will trigger a cjs rebuild automatically. That way if I have the module linked to cjs consumers, I don't have to manually trigger rebuilds.
Would you be interested in that addition and do you have any thoughts on how you would like that done?
To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:
.travis.yml
If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.
Greenkeeper has checked the engines
key in any package.json
file, the .nvmrc
file, and the .travis.yml
file, if present.
engines
was only updated if it defined a single version, not a range..nvmrc
was updated to Node.js 10.travis.yml
was only changed if there was a root-level node_js
that didn’t already include Node.js 10, such as node
or lts/*
. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.For many simpler .travis.yml
configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
rimraf cjs/* && ascjs esm cjs
/Users/bret/littlstar/sdk-js/node_modules/ascjs/index.js:137
}${specifier.local.name}${EOL}`;
^
TypeError: Cannot read property 'name' of undefined
at /Users/bret/littlstar/sdk-js/node_modules/ascjs/index.js:137:26
at Array.forEach (<anonymous>)
at Object.ExportNamedDeclaration (/Users/bret/littlstar/sdk-js/node_modules/ascjs/index.js:132:21)
at /Users/bret/littlstar/sdk-js/node_modules/ascjs/index.js:171:37
at Array.forEach (<anonymous>)
at parse (/Users/bret/littlstar/sdk-js/node_modules/ascjs/index.js:169:23)
at ascjs (/Users/bret/littlstar/sdk-js/node_modules/ascjs/bin.js:6:18)
at /Users/bret/littlstar/sdk-js/node_modules/ascjs/bin.js:99:25
It throws when I try to transform this file:
export * as commands from './commands/index.js'
Reverting to 4.0.2 (and lower) and the transform continues to work. Not a show stopper on my end, work arounds aplenty.
Digging into what change might have caused this, and what that change changed.
The babylon
project has been archived, hence it'd be wise to switch into @babel/parser
instead, as that's the one updated.
However, there are various hcanges I've no idea about, so I'll need to investigate what changed, what breaks, what works, etc etc.
3.0.8
to 3.0.9
.This version is covered by your current version range and after updating it in your project the build failed.
coveralls is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 15 commits.
2e2b108
bump version
50913ed
Remove the now unused istanbul and mocha-lcov-reporter devDependencies
1bceeff
Revert #243.
4aa11a2
Remove snyk.
33eccc3
Revert "CI: use npm ci
on Node.js >=8."
236529b
Update logger.js
3a90b07
fix equality operator in logger.js
bbe2de5
Update package.json
07ef879
Fix logger regression.
f58f8b9
README.md: Add GitHub Actions CI info.
0488f10
Tweak README.md
be79dab
CI: use npm ci
on Node.js >=8.
ef51945
CI: Add Windows testing and lint
c202346
Fix Windows tests again.
3d82534
use Coveralls GitHub action
See the full diff
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
LinkeDOM can't build anymore with latest ascjs ... which is a bummer ... all good up to 6.0.1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.