rollup-plugin-swc3
Advanced tools
Comparing version 0.5.0 to 0.6.0-canary.0
@@ -10,4 +10,3 @@ 'use strict'; | ||
var deepmerge = require('deepmerge'); | ||
var JoyCon = require('joycon'); | ||
var jsoncParser = require('jsonc-parser'); | ||
var getTsconfig = require('get-tsconfig'); | ||
@@ -17,38 +16,17 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs); | ||
var path__default = /*#__PURE__*/_interopDefaultLegacy(path); | ||
var deepmerge__default = /*#__PURE__*/_interopDefaultLegacy(deepmerge); | ||
var JoyCon__default = /*#__PURE__*/_interopDefaultLegacy(JoyCon); | ||
const joycon = new JoyCon__default["default"](); | ||
joycon.addLoader({ | ||
test: /\.json$/, | ||
load: async (file)=>{ | ||
const content = await fs__default["default"].promises.readFile(file, { | ||
encoding: 'utf-8' | ||
}); | ||
return jsoncParser.parse(content); | ||
const getOptions = (cwd, tsconfig)=>{ | ||
if (tsconfig && path__default["default"].isAbsolute(tsconfig)) { | ||
var _compilerOptions; | ||
return (_compilerOptions = getTsconfig.parseTsconfig(tsconfig).compilerOptions) !== null && _compilerOptions !== void 0 ? _compilerOptions : {}; | ||
} | ||
}); | ||
const getOptions = async (cwd, tsconfig)=>{ | ||
// joycon has its builtin-cache support | ||
const { data , path } = await joycon.load([ | ||
tsconfig || 'tsconfig.json', | ||
'jsconfig.json' | ||
], cwd); | ||
if (path && data) { | ||
const { importHelpers , esModuleInterop , experimentalDecorators , emitDecoratorMetadata , jsx , jsxFactory , jsxFragmentFactory , jsxImportSource , target , baseUrl , paths } = data.compilerOptions || {}; | ||
return { | ||
importHelpers, | ||
esModuleInterop, | ||
experimentalDecorators, | ||
emitDecoratorMetadata, | ||
jsx, | ||
jsxFactory, | ||
jsxFragmentFactory, | ||
jsxImportSource, | ||
target, | ||
baseUrl, | ||
paths | ||
}; | ||
let result = getTsconfig.getTsconfig(cwd, tsconfig || 'tsconfig.json'); | ||
// Only fallback to `jsconfig.json` when tsconfig can not be resolved AND custom tsconfig filename is not provided | ||
if (!result && !tsconfig) { | ||
result = getTsconfig.getTsconfig(cwd, 'jsconfig.json'); | ||
} | ||
return {}; | ||
var _compilerOptions1; | ||
return (_compilerOptions1 = result === null || result === void 0 ? void 0 : result.config.compilerOptions) !== null && _compilerOptions1 !== void 0 ? _compilerOptions1 : {}; | ||
}; | ||
@@ -108,3 +86,3 @@ | ||
const isJsx = ext === '.jsx'; | ||
const tsconfigOptions = options.tsconfig === false ? {} : await getOptions(path.dirname(id), options.tsconfig); | ||
const tsconfigOptions = options.tsconfig === false ? {} : getOptions(path.dirname(id), options.tsconfig); | ||
// TODO: SWC is about to add "preserve" jsx | ||
@@ -135,2 +113,3 @@ // https://github.com/swc-project/swc/pull/5661 | ||
baseUrl: tsconfigOptions.baseUrl, | ||
// @ts-expect-error The type from @swc/core is wrong, fixed in https://github.com/swc-project/swc/pull/5811 | ||
paths: tsconfigOptions.paths | ||
@@ -137,0 +116,0 @@ } |
{ | ||
"name": "rollup-plugin-swc3", | ||
"version": "0.5.0", | ||
"version": "0.6.0-canary.0", | ||
"description": "Use SWC with Rollup to transform ESNext and TypeScript code.", | ||
@@ -31,4 +31,3 @@ "main": "dist/index.js", | ||
"deepmerge": "^4.2.2", | ||
"joycon": "^3.1.1", | ||
"jsonc-parser": "^3.2.0" | ||
"get-tsconfig": "^4.2.0" | ||
}, | ||
@@ -38,3 +37,3 @@ "devDependencies": { | ||
"@rollup/plugin-json": "^4.1.0", | ||
"@swc/core": "^1.2.246", | ||
"@swc/core": "^1.2.249", | ||
"@types/chai": "^4.3.3", | ||
@@ -41,0 +40,0 @@ "@types/mocha": "^9.1.1", |
@@ -82,6 +82,8 @@ <div align="center"> | ||
- The configuration your passed to `rollup-plugin-swc` will always have the highest priority (higher than `tsconfig.json`/`jsconfig.json`). | ||
- `rollup-plugin-swc` will find the nearest `tsconfig.json`/`jsconfig.json` from the file that is currently being transpiled (just like `tsc`). | ||
- With `tsconfig` option, you can also provide a custom filename (E.g. `tsconfig.rollup.json`, `jsconfig.compile.json`) for `rollup-plugin-swc` to find and resolve. | ||
- You can also provide a full path (E.g. `/path/to/your/tsconfig.json`) to `tsconfig` option, and `rollup-plugin-swc` will only use the provided path as a single source of truth. | ||
- You can stop `rollup-plugin-swc` from reading `tsconfig.json`/`jsconfig.json` by setting `tsconfig` option to `false`. | ||
- You can provide a custom `tsconfig.json`/`jsconfig.json` file by setting `tsconfig` option to a `string`. | ||
- `jsconfig.json` will be ignored if `tsconfig.json` and `jsconfig.json` both exist. | ||
- The `extends` of `tsconfig.json`/`jsconfig.json` is not supported. | ||
- The `extends` of `tsconfig.json`/`jsconfig.json` is ~~not supported~~ now supported. | ||
- `target` will be passed to swc's `jsc.target`. | ||
@@ -88,0 +90,0 @@ - `jsxImportSource`, `jsxFactory`, and `jsxFragmentFactory` will be passed to swc's `jsc.transform.react.importSource`, `jsc.transform.react.pragma` and `jsc.transform.react.pragmaFrag`. |
@@ -90,3 +90,3 @@ import type { Plugin } from 'rollup'; | ||
? {} | ||
: await getOptions(dirname(id), options.tsconfig); | ||
: getOptions(dirname(id), options.tsconfig); | ||
@@ -121,2 +121,3 @@ // TODO: SWC is about to add "preserve" jsx | ||
baseUrl: tsconfigOptions.baseUrl, | ||
// @ts-expect-error The type from @swc/core is wrong, fixed in https://github.com/swc-project/swc/pull/5811 | ||
paths: tsconfigOptions.paths | ||
@@ -123,0 +124,0 @@ } |
@@ -1,62 +0,19 @@ | ||
import fs from 'fs'; | ||
import JoyCon from 'joycon'; | ||
import { parse } from 'jsonc-parser'; | ||
import { getTsconfig, parseTsconfig } from 'get-tsconfig'; | ||
import path from 'path'; | ||
const joycon = new JoyCon(); | ||
export const getOptions = ( | ||
cwd: string, | ||
tsconfig?: string | ||
) => { | ||
if (tsconfig && path.isAbsolute(tsconfig)) { | ||
return parseTsconfig(tsconfig).compilerOptions ?? {}; | ||
} | ||
joycon.addLoader({ | ||
test: /\.json$/, | ||
load: async (file) => { | ||
const content = await fs.promises.readFile(file, { encoding: 'utf-8' }); | ||
return parse(content); | ||
let result = getTsconfig(cwd, tsconfig || 'tsconfig.json'); | ||
// Only fallback to `jsconfig.json` when tsconfig can not be resolved AND custom tsconfig filename is not provided | ||
if (!result && !tsconfig) { | ||
result = getTsconfig(cwd, 'jsconfig.json'); | ||
} | ||
}); | ||
export const getOptions = async ( | ||
cwd: string, | ||
tsconfig?: string | ||
): Promise<{ | ||
importHelpers?: boolean, | ||
esModuleInterop?: boolean, | ||
experimentalDecorators?: boolean, | ||
emitDecoratorMetadata?: boolean, | ||
jsx?: 'preserve' | 'react' | 'react-jsx' | 'react-jsxdev' | 'react-native', | ||
jsxFactory?: string, | ||
jsxFragmentFactory?: string, | ||
jsxImportSource?: string, | ||
target?: string, | ||
baseUrl?: string, | ||
paths?: { [from: string]: [string] } | ||
}> => { | ||
// joycon has its builtin-cache support | ||
const { data, path } = await joycon.load([tsconfig || 'tsconfig.json', 'jsconfig.json'], cwd); | ||
if (path && data) { | ||
const { | ||
importHelpers, | ||
esModuleInterop, | ||
experimentalDecorators, | ||
emitDecoratorMetadata, | ||
jsx, | ||
jsxFactory, | ||
jsxFragmentFactory, | ||
jsxImportSource, | ||
target, | ||
baseUrl, | ||
paths | ||
} = data.compilerOptions || {}; | ||
return { | ||
importHelpers, | ||
esModuleInterop, | ||
experimentalDecorators, | ||
emitDecoratorMetadata, | ||
jsx, | ||
jsxFactory, | ||
jsxFragmentFactory, | ||
jsxImportSource, | ||
target, | ||
baseUrl, | ||
paths | ||
}; | ||
} | ||
return {}; | ||
return result?.config.compilerOptions ?? {}; | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5
213
35578
513
+ Addedget-tsconfig@^4.2.0
+ Addedget-tsconfig@4.8.1(transitive)
+ Addedresolve-pkg-maps@1.0.0(transitive)
- Removedjoycon@^3.1.1
- Removedjsonc-parser@^3.2.0
- Removedjoycon@3.1.1(transitive)
- Removedjsonc-parser@3.3.1(transitive)