Skip to content

ref!: move to ESM for 2025 #28

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

Merged
merged 3 commits into from
Dec 19, 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
9 changes: 1 addition & 8 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@






{
"module": true,
"browser": true,
"node": true,
"esversion": 11,
"curly": true,
"sub": true,


"bitwise": true,
"eqeqeq": true,
"forin": true,
Expand All @@ -23,7 +17,6 @@
"plusplus": true,
"undef": true,
"unused": "vars",
"strict": true,
"maxdepth": 4,
"maxstatements": 100,
"maxcomplexity": 20
Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@ Turn on transpile-free type hinting for your vanilla JS projects #JSWithTypes
npm init
```
2. Turn on type linting 💪

```sh
# Create a properly configured `jsconfig.json`
npx jswt init
npx -p jswt@2.x -- jswt init

# Install @types/node, if needed
npm install --save '@types/node'
```

3. Profit!

Works with **VS Code** out-of-the-box, and
[Vim + ale](https://webinstall.dev/vim-essentials).

## CommonJS vs ESM

Use v1 for CommonJS, or v2 for ESM.

## Watch the Presentation!

[![JS with Types conference title slide](https://jswithtypes.com/assets/utahjs-conf-2022-jswt-title-yt.png)](https://jswithtypes.com/)
Expand Down Expand Up @@ -49,13 +58,14 @@ Your project will look something like this:
npx -p typescript@5.x -- \
tsc --init \
--allowJs --alwaysStrict --checkJs \
--moduleResolution node \
--noEmit --noImplicitAny --target es2022 \
--module nextnode --moduleResolution nextnode \
--noEmit --noImplicitAny --target es2024 \
--typeRoots './typings,./node_modules/@types'
```
2. Adds the following keys:
```txt
"include": ["*.js", "bin/**/*.js", "lib/**/*.js", "src/**/*.js"]`
"paths": { "foo": ["./foo.js"], "foo/*": ["./*"] },
"include": ["*.js", "bin/**/*.js", "lib/**/*.js", "src/**/*.js"]`,
"exclude": ["node_modules"]
```
3. Renames `tsconfig.json` to `jsconfig.json` \
Expand Down
22 changes: 10 additions & 12 deletions bin/_walk.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use strict";
import Fs from "node:fs/promises";
import Path from "node:path";

const Fs = require("node:fs/promises");
const Path = require("node:path");
let Walk = {};
Walk.skipDir = new Error("skip this directory");

const skipDir = new Error("skip this directory");
const _withFileTypes = { withFileTypes: true };
let _withFileTypes = { withFileTypes: true };

/** @typedef {import('fs').Dirent} Dirent */

Expand All @@ -24,7 +24,7 @@ const _withFileTypes = { withFileTypes: true };
* @param {Dirent} [_dirent]
* @returns {Promise<void>}
*/
const walk = async (pathname, walkFunc, _dirent) => {
Walk.walk = async function (pathname, walkFunc, _dirent) {
let err;

// special case of the very first run
Expand All @@ -41,7 +41,7 @@ const walk = async (pathname, walkFunc, _dirent) => {

// run the user-supplied function and either skip, bail, or continue
let cont = await walkFunc(err, pathname, _dirent).catch(function (err) {
if (skipDir === err) {
if (Walk.skipDir === err) {
return false;
}
throw err;
Expand All @@ -65,11 +65,9 @@ const walk = async (pathname, walkFunc, _dirent) => {
);

for (let dirent of dirents) {
await walk(Path.join(pathname, dirent.name), walkFunc, dirent);
let path = Path.join(pathname, dirent.name);
await Walk.walk(path, walkFunc, dirent);
}
};

module.exports = {
walk,
skipDir,
};
export default Walk;
Loading
Loading