Skip to content

Commit

Permalink
Package helpers in helpers-string.js as a commonjs module so that bun…
Browse files Browse the repository at this point in the history
…dlers may include it as content
  • Loading branch information
rpetrich committed Apr 20, 2019
1 parent 1a23976 commit 9075716
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ babel-plugin-transform-async-to-promises-*.tgz
coverage
async-to-promises.js
async-to-promises.js.map
helpers-string.js
1 change: 1 addition & 0 deletions .npmignore
@@ -1,6 +1,7 @@
*.test.js
babel-plugin-transform-async-to-promises-*.tgz
coverage
generate-helpers-string.js
.travis.yml
*.ts
tests/
Expand Down
4 changes: 1 addition & 3 deletions async-to-promises.ts
@@ -1,7 +1,6 @@
import { ArrowFunctionExpression, AwaitExpression, BlockStatement, CallExpression, ClassMethod, LabeledStatement, Node, Expression, FunctionDeclaration, Statement, Identifier, ForStatement, ForInStatement, SpreadElement, ReturnStatement, ForOfStatement, Function, FunctionExpression, MemberExpression, NumericLiteral, ThisExpression, SwitchCase, Program, VariableDeclaration, VariableDeclarator, StringLiteral, BooleanLiteral, Pattern, LVal, YieldExpression } from "babel-types";
import { NodePath, Scope, Visitor } from "babel-traverse";
import { readFileSync } from "fs";
import { join } from "path";
import { code as helperCode } from "./helpers-string";

// Configuration types
interface AsyncToPromisesConfiguration {
Expand Down Expand Up @@ -2854,7 +2853,6 @@ export default function({ types, template, traverse, transformFromAst, version }
if (!helpers) {
// Read helpers from ./helpers.js
const newHelpers: { [name: string]: Helper } = {};
const helperCode = readFileSync(join(__dirname, "helpers.js")).toString();
const helperAst = require(isNewBabel ? "@babel/core" : "babylon").parse(helperCode, { sourceType: "module" });
transformFromAst(helperAst, helperCode, {
babelrc: false, plugins: [{
Expand Down
5 changes: 5 additions & 0 deletions generate-helpers-string.js
@@ -0,0 +1,5 @@
const { readFileSync, writeFileSync } = require("fs");
const { join } = require("path");

const helperCode = readFileSync("helpers.js").toString();
writeFileSync("helpers-string.js", `exports.__esModule = true;\nexports.code = ${JSON.stringify(helperCode)};\n`);
1 change: 1 addition & 0 deletions helpers-string.d.ts
@@ -0,0 +1 @@
export const code: string;
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -4,7 +4,7 @@
"description": "Transform async/await to promise chains",
"main": "async-to-promises.js",
"scripts": {
"prepare": "tsc --strict --lib es5,es6,es2016 --types node --module commonjs --sourceMap async-to-promises.ts",
"prepare": "tsc --strict --lib es5,es6,es2016 --types node --module commonjs --sourceMap async-to-promises.ts && node ./generate-helpers-string.js",
"test": "jest",
"test:coverage": "jest --coverage"
},
Expand Down

0 comments on commit 9075716

Please sign in to comment.