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

feat: esm interop for compiled files #4

Merged
merged 1 commit into from
Jul 11, 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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "oxc-node",
"version": "0.0.0",
"private": true,
"packageManager": "pnpm@9.4.0",
"packageManager": "pnpm@9.5.0",
"devDependencies": {
"@napi-rs/cli": "^3.0.0-alpha.56",
"@napi-rs/wasm-runtime": "^0.2.4",
Expand All @@ -14,6 +14,7 @@
"emnapi": "^1.2.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.7",
"npm-run-all2": "^6.2.2",
"oxlint": "^0.5.2",
"prettier": "^3.3.2",
"typescript": "^5.5.3"
Expand All @@ -22,7 +23,7 @@
"build": "napi build --platform --release -o packages/core",
"format": "taplo fmt && prettier --write . && cargo fmt",
"lint": "oxlint",
"test": "pnpm --filter=integrate-module run test:module",
"test": "pnpm --filter=integrate-module* run test",
"prepare": "husky"
},
"lint-staged": {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ export interface LoadContext {

export interface LoadFnOutput {
format: string
/** A signal that this hook intends to terminate the chain of `resolve` hooks. */
shortCircuit?: boolean
source?: string | Uint8Array | Buffer | null
responseURL?: string
}

export declare function resolve(specifier: string, context: ResolveContext, nextResolve: (arg0: string, arg1?: ResolveContext | undefined | null) => ResolveFnOutput | Promise<ResolveFnOutput>): ResolveFnOutput | Promise<ResolveFnOutput>
Expand Down
3 changes: 2 additions & 1 deletion packages/integrate-module-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"simple-git": "^3.25.0",
"ts-node": "^10.9.2"
"ts-node": "^10.9.2",
"tsx": "^4.16.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare const exports: {
default: () => string
}

export default exports
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// this undesirable output was commonly generated by babel w browser-breaking
// defineProperty and default.default definitions

/* eslint-disable */
'use strict'

Object.defineProperty(exports, '__esModule', {
value: true,
})
exports['default'] = void 0

function _typeof(obj) {
'@babel/helpers - typeof'
if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') {
_typeof = function _typeof(obj) {
return typeof obj
}
} else {
_typeof = function _typeof(obj) {
return obj && typeof Symbol === 'function' && obj.constructor === Symbol && obj !== Symbol.prototype
? 'symbol'
: typeof obj
}
}
return _typeof(obj)
}

var _default = function _default() {
return 'default.default'
}

exports['default'] = _default
/* eslint-enable */
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"description": "problematic cjs file type generated by babel",
"main": "./index.js",
"types": "./index.d.ts"
}
5 changes: 5 additions & 0 deletions packages/integrate-module-bundler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { bar } from './subdirectory/bar'
import { baz } from './subdirectory/index'
import { Component } from './component'
import './js-module'
import babelGeneratedDoubleDefault from './babel-generated-double-default'

const { foo: fooWithQuery } = await import(`./foo.js?q=${Date.now()}`)

Expand Down Expand Up @@ -56,3 +57,7 @@ await test('resolve @napi-rs projects', () => {
await test('resolve simple-git', () => {
assert.ok(simpleGit)
})

await test('import default from babel-generated cjs file', () => {
assert.equal(babelGeneratedDoubleDefault.default(), 'default.default')
})
2 changes: 1 addition & 1 deletion packages/integrate-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"p-timeout": "^6.1.2"
},
"scripts": {
"test:module": "node --import @oxc/node-core/register ./src/index.ts"
"test": "node --import @oxc/node-core/register ./src/index.ts"
},
"devDependencies": {
"@napi-rs/simple-git": "^0.1.16",
Expand Down
Loading