Skip to content

Commit 6b645f9

Browse files
committed
feat: add conditional exports
1 parent 79d7ada commit 6b645f9

File tree

11 files changed

+66
-88
lines changed

11 files changed

+66
-88
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/coverage
22
/.nyc_output
33
node_modules
4-
/es
4+
/mjs
5+
/cjs
6+
/types
57
.eslintcache
68
*.js
79
*.js.flow

.npmignore

Lines changed: 0 additions & 12 deletions
This file was deleted.

package.json

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,36 @@
33
"version": "0.0.0-development",
44
"description": "super powerful structural search and replace for JavaScript and TypeScript to automate your refactoring",
55
"bin": {
6-
"astx": "cli/index.js"
6+
"astx": "./cjs/cli/index.js"
77
},
8+
"exports": {
9+
"./package.json": "./package.json",
10+
".": {
11+
"import": "./mjs/index.mjs",
12+
"require": "./cjs/index.js",
13+
"types": "./types/index.d.ts"
14+
},
15+
"./node": {
16+
"import": "./mjs/node/index.mjs",
17+
"require": "./cjs/node/index.js",
18+
"types": "./types/index.d.ts"
19+
},
20+
"./cli": {
21+
"import": "./mjs/cli/index.mjs",
22+
"require": "./cjs/cli/index.js",
23+
"types": "./types/index.d.ts"
24+
}
25+
},
26+
"files": [
27+
"mjs",
28+
"cjs",
29+
"types"
30+
],
831
"astx": {
932
"parser": "babel"
1033
},
11-
"main": "index.js",
34+
"main": "./cjs/index.js",
35+
"types": "./types/index.d.ts",
1236
"sideEffects": false,
1337
"scripts": {
1438
"cli": "babel-node --extensions .ts src/cli/index.ts",
@@ -18,12 +42,13 @@
1842
"prettier:check": "prettier --list-different $npm_package_config_prettier",
1943
"tsc": "tsc",
2044
"tsc:watch": "npm run tsc -- --watch",
21-
"clean": "rimraf es lib $(cd src; ls) *.js *.d.ts *.js.flow",
22-
"build": "npm run clean && npm run build:types && npm run build:mjs && npm run check:mjs && npm run build:cjs",
23-
"build:types": "tsc -p tsconfig.build.json && tsc -p tsconfig.build.json --outDir es && copy 'src/**/*.js.flow' . && copy 'src/**/*.js.flow' es",
24-
"build:mjs": "cross-env OUTPUT_ESM=1 babel src --out-dir es --out-file-extension .mjs --extensions .ts --source-maps inline && babel-node --extensions .ts src/cli/index.ts -t convertImportsToMjs.ts --workers 1 --parser babel --no-gitignore -y 'es/**/*.mjs'",
25-
"check:mjs": "node es/index.mjs && node es/node/index.mjs && node es/cli/index.mjs --help",
26-
"build:cjs": "cross-env BABEL_ENV=es5 babel src --out-dir . --extensions \".ts\"",
45+
"clean": "rimraf mjs cjs types",
46+
"build": "npm run clean && npm run build:types && npm run build:cjs && npm run build:mjs && npm run check:mjs",
47+
"build:types": "tsc -p tsconfig.build.json && mkdir -p cjs && copy 'src/**/*.js.flow' cjs && mkdir -p mjs && copy 'src/**/*.js.flow' mjs",
48+
"build:cjs": "cross-env BABEL_ENV=es5 babel src --out-dir cjs --extensions .ts",
49+
"check:cjs": "node cjs/index.js && node cjs/node/index.js && node cjs/cli/index.js --help",
50+
"build:mjs": "cross-env OUTPUT_ESM=1 babel src --out-dir mjs --out-file-extension .mjs --extensions .ts --source-maps inline && babel-node --extensions .ts src/cli/index.ts -t convertImportsToMjs.ts --workers 1 --parser babel --no-gitignore -y 'mjs/**/*.mjs'",
51+
"check:mjs": "node mjs/index.mjs && node mjs/node/index.mjs && node mjs/cli/index.mjs --help",
2752
"test": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=lcov --reporter=text mocha $npm_package_config_mocha",
2853
"test:watch": "cross-env NODE_ENV=test BABEL_ENV=test mocha $npm_package_config_mocha --watch",
2954
"test:debug": "cross-env NODE_ENV=test BABEL_ENV=test mocha --inspect-brk $npm_package_config_mocha",

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@ export {
1818
type CompiledReplacement,
1919
} from './compileReplacement'
2020
export { type Backend } from './backend/Backend'
21-
export { type NodePath, type Node } from './types'
21+
export {
22+
type NodePath,
23+
type Node,
24+
type Expression,
25+
type Statement,
26+
type Location,
27+
type File,
28+
} from './types'
2229
export { default as getBabelAutoBackend } from './babel/getBabelAutoBackend'
2330
export { default as getBabelBackend } from './babel/getBabelBackend'
2431
export { default as BabelBackend } from './babel/BabelBackend'
2532
export { default as getRecastBackend } from './recast/getRecastBackend'
2633
export { default as RecastBackend } from './recast/RecastBackend'
2734
export { default as CodeFrameError } from './util/CodeFrameError'
2835
export { default as CompilePathError } from './util/CompilePathError'
29-
export { type AstxConfig } from './AstxConfig'
36+
export { type AstxConfig, AstxConfigType } from './AstxConfig'

src/node/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
export { default as AstxWorkerPool } from './AstxWorkerPool'
2-
export { default as runTransform } from './runTransform'
3-
export { default as runTransformOnFile } from './runTransformOnFile'
2+
export {
3+
default as runTransform,
4+
type RunTransformOptions,
5+
} from './runTransform'
6+
export {
7+
default as runTransformOnFile,
8+
type RunTransformOnFileOptions,
9+
} from './runTransformOnFile'
410
export {
511
type IpcPath,
612
type IpcNode,

src/node/runTransform.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ import { astxCosmiconfig } from './astxCosmiconfig'
66
import { Transform, TransformResult } from '../Astx'
77
import Gitignore from 'gitignore-fs'
88

9+
export type RunTransformOptions = {
10+
gitignore?: Gitignore | null
11+
transform?: Transform
12+
transformFile?: string
13+
paths?: readonly string[]
14+
cwd?: string
15+
config?: Partial<AstxConfig>
16+
signal?: AbortSignal
17+
}
18+
919
export default async function* runTransform({
1020
gitignore,
1121
transform: _transform,
@@ -14,15 +24,7 @@ export default async function* runTransform({
1424
cwd = process.cwd(),
1525
config,
1626
signal,
17-
}: {
18-
gitignore?: Gitignore | null
19-
transform?: Transform
20-
transformFile?: string
21-
paths?: readonly string[]
22-
cwd?: string
23-
config?: Partial<AstxConfig>
24-
signal?: AbortSignal
25-
}): AsyncIterable<TransformResult> {
27+
}: RunTransformOptions): AsyncIterable<TransformResult> {
2628
clearCache()
2729
astxCosmiconfig.clearSearchCache()
2830

src/util/resolveGlobsAndDirs.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

tsconfig.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
1818
// "sourceMap": true, /* Generates corresponding '.map' file. */
1919
// "outFile": "./", /* Concatenate and emit output to single file. */
20-
"outDir": "./" /* Redirect output structure to the directory. */,
20+
"outDir": "./types" /* Redirect output structure to the directory. */,
2121
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
2222
// "composite": true, /* Enable project compilation */
2323
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
@@ -50,8 +50,7 @@
5050
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
5151
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
5252
"typeRoots": [
53-
"./node_modules/@types",
54-
"./types"
53+
"./node_modules/@types"
5554
] /* List of folders to include type definitions from. */,
5655
// "types": [], /* Type declaration files to be included in compilation. */
5756
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,

types/glob-gitignore/index.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

types/require-glob/index.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

types/resolve/index.d.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)