Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: legacy types #4

Merged
merged 9 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Changelog

## 0.6.10

PINNED: traverse@0.6.9

### Patch Changes

Fix types for neotraverse/legacy. Now both CJS and ESM are properly typed. CAVEAT: ESM import in typescript doesn't provide `TraverseContext` and `TraverseOptions` types. Import that from `neotraverse` instead.

Fresh start. Check out the [CHANGELOG](https://github.com/ljharb/js-traverse/blob/main/CHANGELOG.md#v069---2024-04-08) 0.6.9 for a list of changes prior to this release.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,19 @@ Call this function before each of the children are traversed.

Call this function after each of the children are traversed.

# Troubleshooting

## Next.js

Next.js with Webpack automatically looks for CommonJS version of `neotraverse` and fails to build. Only option is to use `neotraverse/legacy` instead of `neotraverse`.

CAVEAT: `neotraverse/legacy` does not provide additional types, so you need to import `TraverseContext` and `TraverseOptions` from `neotraverse` instead of `traverse`.

```ts
import traverse from 'neotraverse';
import type { TraverseContext, TraverseOptions } from 'neotraverse';
```

# license

MIT
6 changes: 3 additions & 3 deletions examples/try-esm/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Traverse } from 'neotraverse/modern';
import traverse from 'neotraverse/legacy';

const obj = {
a: 1,
Expand All @@ -13,8 +13,8 @@ const obj = {
},
};

new Traverse(obj).forEach((ctx, node) => {
if (node === 6) ctx.update(68);
traverse(obj).forEach(function (node) {
if (node === 6) this.update(68);
});

console.log(obj);
2 changes: 1 addition & 1 deletion examples/try-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"license": "ISC",
"description": "",
"dependencies": {
"neotraverse": "0.6.9-test.1"
"neotraverse": "https://pkg.pr.new/PuruVJ/neotraverse@d47bc4c"
}
}
11 changes: 6 additions & 5 deletions examples/try-esm/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion examples/try/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ const obj = {
},
};

traverse.forEach(obj, (node) => {});
traverse(obj).forEach((node) => {});

console.log(obj);
2 changes: 1 addition & 1 deletion examples/try/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"license": "ISC",
"description": "",
"dependencies": {
"neotraverse": "0.0.5"
"neotraverse": "https://pkg.pr.new/PuruVJ/neotraverse@d47bc4c"
}
}
11 changes: 6 additions & 5 deletions examples/try/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "neotraverse",
"version": "0.6.9-next.0",
"version": "0.6.10",
"description": "traverse and transform objects by visiting every node on a recursive walk",
"main": "dist/legacy/legacy.cjs",
"type": "module",
Expand All @@ -25,12 +25,17 @@
"development": "./dist/modern/modern.js",
"default": "./dist/modern/modern.js"
},
"default": "./dist/min/index.js"
"default": "./dist/modern/index.js"
},
"./legacy": {
"types": "./dist/legacy/legacy.d.ts",
"node": "./dist/legacy/legacy.cjs",
"import": "./dist/legacy/legacy.mjs",
"require": {
"types": "./dist/legacy/legacy.d.cts",
"default": "./dist/legacy/legacy.cjs"
},
"import": {
"types": "./dist/legacy/legacy.d.ts",
"default": "./dist/legacy/legacy.mjs"
},
"default": "./dist/legacy/index.cjs"
},
"./package.json": "./package.json"
Expand Down
3 changes: 2 additions & 1 deletion src/legacy.cts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
const traverse = require('./index.ts');
const traverse = require('./index.js');

module.exports = traverse.default;
4 changes: 3 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export default defineConfig([
return { js: ctx.format === 'cjs' ? '.cjs' : '.mjs' };
},
dts: {
banner: `export type { TraverseContext, TraverseOptions } from '..';`,
banner: `declare const traverse: typeof import('..')['default'];
export = traverse;
`,
},
sourcemap: false,
clean: true,
Expand Down