Skip to content

Commit

Permalink
20.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloSzx committed Jan 2, 2024
1 parent bf703ab commit 26add0d
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 53 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/canary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 20.x
- name: Setup Node.js 20.5.1
uses: actions/setup-node@v2
with:
node-version: 20.x
node-version: 20.5.1

- uses: oven-sh/setup-bun@v1

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 20.x
- name: Setup Node.js 20.5.1
uses: actions/setup-node@v2
with:
node-version: 20.x
node-version: 20.5.1

- uses: oven-sh/setup-bun@v1

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
node_version: [18, 20]
node_version: [18, 20.5.1]
steps:
- name: Checkout Repo
uses: actions/checkout@master
Expand Down
8 changes: 4 additions & 4 deletions examples/basic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ console.log(Foo);

console.log(Bar);

export { Foo, Bar };
// export { Foo, Bar };

export { B } from './other';
// export { B } from './other';

import { Hello } from 'aliased-deep';
// import { Hello } from 'aliased-deep';

console.log(Hello);
// console.log(Hello);
11 changes: 11 additions & 0 deletions packages/bob-tsm/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ async function main() {
minify: false,
},
}),
buildCode({
entryPoints: ['./src/register.ts'],
clean: false,
format: 'cjs',
outDir: 'lib',
target: 'node18',
sourcemap: false,
esbuild: {
minify: false,
},
}),
buildCode({
entryPoints: ['./src/loader.ts'],
clean: false,
Expand Down
45 changes: 1 addition & 44 deletions packages/bob-tsm/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { promises } from 'fs';
import { dirname, extname } from 'path';
import { fileURLToPath, pathToFileURL, URL } from 'url';
import type { Config, Extension, Options } from './config';
import { defaults, fileExists, finalize, nodeMajor, nodeMinor } from './utils';
import { defaults, fileExists, finalize } from './utils';

if (!process.env.KEEP_LOADER_ARGV) {
const loaderArgIndex = process.execArgv.findIndex(v => v.startsWith('--loader'));
Expand All @@ -16,8 +16,6 @@ export const tsconfigPathsHandler = process.env.TSCONFIG_PATHS
? import('./deps/typescriptPaths.js').then(({ createHandler }) => createHandler())
: undefined;

const HAS_UPDATED_HOOKS = nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 12);

let config: Config;
let esbuild: typeof import('esbuild');

Expand All @@ -37,14 +35,6 @@ type Resolve = (
fallback: Resolve
) => Promisable<{ url: string; format?: Format | null; shortCircuit: boolean }>;

type Inspect = (url: string, context: object, fallback: Inspect) => Promisable<{ format: Format }>;

type Transform = (
source: Source,
context: Record<'url' | 'format', string>,
fallback: Transform
) => Promisable<{ source: Source }>;

type Load = (
url: string,
context: { format: Format | null | undefined },
Expand Down Expand Up @@ -166,17 +156,6 @@ export const resolve: Resolve = async function (specifier, context, defaultResol
return defaultResolve(specifier, context, defaultResolve);
};

export const getFormat: Inspect | undefined = HAS_UPDATED_HOOKS
? undefined
: async function (uri, context, fallback) {
let options = await toOptions(uri);
if (options == null) return fallback(uri, context, fallback);

if (uri.endsWith('.d.ts')) return { format: 'module' };

return { format: options.format === 'cjs' ? 'commonjs' : 'module' };
};

function getDirnames(url: string) {
const filename = fileURLToPath(url);

Expand Down Expand Up @@ -211,25 +190,3 @@ export const load: Load = async function (url, context, defaultLoad) {
shortCircuit: true,
};
};

export const transformSource: Transform | undefined = HAS_UPDATED_HOOKS
? undefined
: async function (source, context, xform) {
let options = await toOptions(context.url);
if (options == null) return xform(source, context, xform);

if (context.url.endsWith('.d.ts')) return { source: '' };

const isModule = context.format === 'module';

// TODO: decode SAB/U8 correctly
esbuild = esbuild || (await import('esbuild'));
let result = await esbuild.transform(source.toString(), {
...options,
define: isModule ? { ...getDirnames(context.url), ...options.define } : options.define,
sourcefile: context.url,
format: isModule ? 'esm' : 'cjs',
});

return { source: result.code };
};
4 changes: 4 additions & 0 deletions packages/bob-tsm/src/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { register } from 'node:module';
import { pathToFileURL } from 'node:url';

register('./loader.mjs', pathToFileURL(__filename));

0 comments on commit 26add0d

Please sign in to comment.