Skip to content
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ jobs:
- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Run lint
run: pnpm lint

- name: Run tests
run: pnpm test
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["rstack.rslint"]
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"scripts": {
"build": "rslib",
"dev": "rslib -w",
"lint": "rslint",
"lint:write": "rslint --fix",
"prebundle": "node ./bin.js",
"prepare": "rslib",
"bump": "npx bumpp",
Expand All @@ -34,6 +36,7 @@
"devDependencies": {
"@astrojs/sitemap": "^3.7.2",
"@rslib/core": "0.21.3",
"@rslint/core": "^0.5.2",
"@rstest/core": "^0.9.10",
"@types/fs-extra": "^11.0.4",
Comment thread
chenjiahan marked this conversation as resolved.
"@types/node": "24.12.2",
Expand Down
100 changes: 100 additions & 0 deletions pnpm-lock.yaml

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

9 changes: 9 additions & 0 deletions rslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig, js, ts } from '@rslint/core';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add jiti or avoid a TypeScript lint config

Because this new config is rslint.config.ts, pnpm lint only works on Node versions with native TypeScript config loading. I checked @rslint/core's config loader: for .ts/.mts configs it uses native loading only when process.features.typescript is present (Node >=22.6) and otherwise requires the optional peer jiti; this repo has no engine pin to Node 22+ and existing tooling supports Node 20, so developers/CI variants on Node 20 will fail before linting unless jiti is added or the config is changed to .mjs.

Useful? React with 👍 / 👎.


export default defineConfig([
{
ignores: ['compiled/**'],
},
js.configs.recommended,
ts.configs.recommended,
]);
6 changes: 4 additions & 2 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function findDepPath(name: string) {
}

return entry;
} catch (err) {
} catch {
return null;
}
}
Expand Down Expand Up @@ -156,7 +156,9 @@ export function findDirectTypeFile(filepath: string) {
for (const f of list) {
try {
return require.resolve(f, { paths: [cwd] });
} catch {}
} catch {
continue;
}
}
};
switch (ext) {
Expand Down
33 changes: 26 additions & 7 deletions src/prebundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,30 @@ async function emitIndex(code: string, distPath: string, prettier?: boolean) {
}
}

const getTypes = (json: Record<string, string>): string | null =>
type PackageJsonLike = {
types?: unknown;
typing?: unknown;
typings?: unknown;
exports?: {
'.'?: PackageJsonLike;
};
};

const getPackageJsonField = (
json: PackageJsonLike,
key: 'types' | 'typing' | 'typings',
) => {
const value = json[key];
return typeof value === 'string' ? value : null;
};

const getTypes = (json: PackageJsonLike | null | undefined): string | null =>
(json &&
(json.types ||
json.typing ||
json.typings ||
(getPackageJsonField(json, 'types') ||
getPackageJsonField(json, 'typing') ||
getPackageJsonField(json, 'typings') ||
// for those who use `exports` only
getTypes((json as any).exports?.['.']))) ||
getTypes(json.exports?.['.']))) ||
null;

async function emitDts(task: ParsedTask, externals: Record<string, string>) {
Expand Down Expand Up @@ -145,7 +162,7 @@ async function emitDts(task: ParsedTask, externals: Record<string, string>) {
// Avoid extra work
checkJs: false,
// Ensure we can parse the latest code
// @ts-expect-error
// @ts-expect-error rollup-plugin-dts accepts task target values.
target: task.target,
},
}),
Expand Down Expand Up @@ -210,7 +227,9 @@ function emitPackageJson(
// will be `{"type":"module"}` if the output is of esm format
pick(JSON.parse(assets['package.json'].source), ['type']),
);
} catch {}
} catch {
// Keep the picked package fields when ncc emits non-JSON metadata.
}
}

fs.outputFileSync(outputPath, JSON.stringify(pickedPackageJson, null, 2));
Expand Down
Loading