-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
704 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,5 @@ node_modules | |
/types | ||
/api-doc | ||
coverage | ||
/mod.d.ts | ||
/mod.js | ||
/dist | ||
/deno |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Deno users should use mod.ts instead | ||
export * from './deno/index.ts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// For Deno | ||
export * from './deno/index.ts' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,11 @@ | |
"type": "git" | ||
}, | ||
"main": "dist/index.js", | ||
"module": "mod.mjs", | ||
"module": "dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./mod.mjs", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js" | ||
}, | ||
"./package.json": "./package.json", | ||
|
@@ -20,44 +20,51 @@ | |
"files": [ | ||
"dist", | ||
"!**/__test__/**", | ||
"/mod.mjs", | ||
"/mod.js", | ||
"/mod.d.ts" | ||
"/mode.ts", | ||
"/deno" | ||
], | ||
"scripts": { | ||
"test": "jest", | ||
"test:cov": "jest --coverage", | ||
"build": "rollup -c", | ||
"build:deno": "node -r sucrase/register scripts/build-deno.ts", | ||
"build:node": "rollup -c", | ||
"build": "yarn build:deno && yarn build:node", | ||
"toc": "markdown-toc -i README.md", | ||
"prepublishOnly": "npm run build && cp mod.js mod.mjs", | ||
"docs:api": "typedoc --out api-doc --readme none --exclude \"**/__test__/**\" --theme minimal" | ||
}, | ||
"author": "egoist <[email protected]>", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^11.1.0", | ||
"@rollup/plugin-node-resolve": "^7.1.3", | ||
"@types/execa": "^0.9.0", | ||
"@types/jest": "^23.3.9", | ||
"@babel/core": "^7.12.10", | ||
"@babel/plugin-syntax-typescript": "^7.12.1", | ||
"@rollup/plugin-commonjs": "^17.0.0", | ||
"@rollup/plugin-node-resolve": "^11.0.0", | ||
"@types/fs-extra": "^9.0.5", | ||
"@types/jest": "^26.0.19", | ||
"@types/mri": "^1.1.0", | ||
"cz-conventional-changelog": "^2.1.0", | ||
"esbuild": "^0.8.21", | ||
"eslint-config-rem": "^3.0.0", | ||
"events": "^3.0.0", | ||
"execa": "^1.0.0", | ||
"execa": "^5.0.0", | ||
"fs-extra": "^9.0.1", | ||
"globby": "^11.0.1", | ||
"husky": "^1.2.0", | ||
"jest": "^24.9.0", | ||
"lint-staged": "^8.1.0", | ||
"markdown-toc": "^1.2.0", | ||
"mri": "^1.1.1", | ||
"prettier": "^1.15.2", | ||
"rollup": "^2.10.0", | ||
"rollup-plugin-dts": "^1.4.3", | ||
"rollup-plugin-esbuild": "^1.4.1", | ||
"mri": "^1.1.6", | ||
"prettier": "^2.2.1", | ||
"rollup": "^2.34.2", | ||
"rollup-plugin-dts": "^2.0.1", | ||
"rollup-plugin-esbuild": "^2.6.1", | ||
"semantic-release": "^17.3.0", | ||
"ts-jest": "^23.10.5", | ||
"ts-node": "^7.0.1", | ||
"typedoc": "^0.17.6", | ||
"typescript": "^3.9.2" | ||
"sucrase": "^3.16.0", | ||
"ts-jest": "^26.4.4", | ||
"ts-node": "^9.1.1", | ||
"typedoc": "^0.19.2", | ||
"typescript": "^4.1.2" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import path from 'path' | ||
import globby from 'globby' | ||
import fs from 'fs-extra' | ||
import { transformAsync, PluginObj, types as Types } from '@babel/core' | ||
import tsSyntax from '@babel/plugin-syntax-typescript' | ||
|
||
function node2deno(options: { types: typeof Types }): PluginObj { | ||
const t = options.types | ||
return { | ||
name: 'node2deno', | ||
|
||
visitor: { | ||
ImportDeclaration(path) { | ||
const source = path.node.source | ||
if (source.value.startsWith('.')) { | ||
if (source.value.endsWith('/node')) { | ||
source.value = source.value.replace('node', 'deno') | ||
} | ||
source.value += '.ts' | ||
} else if (source.value === 'events') { | ||
source.value = `https://deno.land/[email protected]/node/events.ts` | ||
} else if (source.value === 'mri') { | ||
source.value = `https://cdn.skypack.dev/mri` | ||
} | ||
}, | ||
|
||
IfStatement(path) { | ||
if (path.getSource().includes('@remove-for-deno')) { | ||
path.remove() | ||
} | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
async function main() { | ||
const files = await globby(['**/*.ts', '!**/__test__/**'], { cwd: 'src' }) | ||
await Promise.all( | ||
files.map(async (file) => { | ||
if (file === 'node.ts') return | ||
const content = await fs.readFile(path.join('src', file), 'utf8') | ||
const transformed = await transformAsync(content, { | ||
plugins: [tsSyntax, node2deno], | ||
}) | ||
await fs.outputFile(path.join('deno', file), transformed.code, 'utf8') | ||
}) | ||
) | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error) | ||
process.exitCode = 1 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.