@vitejs/plugin-react
Advanced tools
Comparing version 1.3.2 to 2.0.0-alpha.0
@@ -1,8 +0,5 @@ | ||
import type { ParserOptions } from '@babel/core'; | ||
import type { PluginOption } from 'vite'; | ||
import type { TransformOptions } from '@babel/core'; | ||
import { TransformOptions, ParserOptions } from '@babel/core'; | ||
import { ResolvedConfig, PluginOption } from 'vite'; | ||
export declare type BabelOptions = Omit<TransformOptions, 'ast' | 'filename' | 'root' | 'sourceFileName' | 'sourceMaps' | 'inputSourceMap'>; | ||
export declare interface Options { | ||
interface Options { | ||
include?: string | RegExp | Array<string | RegExp>; | ||
@@ -36,8 +33,4 @@ exclude?: string | RegExp | Array<string | RegExp>; | ||
babel?: BabelOptions; | ||
/** | ||
* @deprecated Use `babel.parserOpts.plugins` instead | ||
*/ | ||
parserPlugins?: ParserOptions['plugins']; | ||
} | ||
declare type BabelOptions = Omit<TransformOptions, 'ast' | 'filename' | 'root' | 'sourceFileName' | 'sourceMaps' | 'inputSourceMap'>; | ||
/** | ||
@@ -47,3 +40,3 @@ * The object type used by the `options` passed to plugins with | ||
*/ | ||
export declare interface ReactBabelOptions extends BabelOptions { | ||
interface ReactBabelOptions extends BabelOptions { | ||
plugins: Extract<BabelOptions['plugins'], any[]>; | ||
@@ -56,10 +49,17 @@ presets: Extract<BabelOptions['presets'], any[]>; | ||
} | ||
declare module 'vite' { | ||
interface Plugin { | ||
api?: { | ||
/** | ||
* Manipulate the Babel options of `@vitejs/plugin-react` | ||
*/ | ||
reactBabel?: (options: ReactBabelOptions, config: ResolvedConfig) => void; | ||
}; | ||
} | ||
} | ||
declare function viteReact(opts?: Options): PluginOption[]; | ||
declare namespace viteReact { | ||
var preambleCode: string; | ||
} | ||
export default viteReact; | ||
export { } | ||
export { BabelOptions, Options, ReactBabelOptions, viteReact as default }; |
{ | ||
"name": "@vitejs/plugin-react", | ||
"version": "1.3.2", | ||
"version": "2.0.0-alpha.0", | ||
"license": "MIT", | ||
@@ -13,14 +13,20 @@ "author": "Evan You", | ||
], | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"scripts": { | ||
"dev": "tsc -p . -w --incremental", | ||
"build": "rimraf dist && run-s build-bundle build-types", | ||
"build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@babel/* --external:@rollup/* --external:resolve --external:react-refresh/* --outfile=dist/index.js && npm run patch-dist", | ||
"patch-dist": "ts-node ../../scripts/patchEsbuildDist.ts dist/index.js viteReact", | ||
"build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp", | ||
"prepublishOnly": "(cd ../vite && npm run build) && npm run build" | ||
"dev": "unbuild --stub", | ||
"build": "unbuild && pnpm run patch-cjs", | ||
"patch-cjs": "ts-node ../../scripts/patchCJS.ts", | ||
"prepublishOnly": "npm run build" | ||
}, | ||
"engines": { | ||
"node": ">=12.0.0" | ||
"node": ">=14.6.0" | ||
}, | ||
@@ -45,3 +51,9 @@ "repository": { | ||
"resolve": "^1.22.0" | ||
}, | ||
"peerDependencies": { | ||
"vite": "^3.0.0-alpha" | ||
}, | ||
"devDependencies": { | ||
"vite": "workspace:*" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
import type { types as t } from '@babel/core' | ||
import fs from 'fs' | ||
import path from 'path' | ||
import type { types as t } from '@babel/core' | ||
@@ -5,0 +5,0 @@ export const runtimePublicPath = '/@react-refresh' |
@@ -5,3 +5,3 @@ import type { ParserOptions, TransformOptions, types as t } from '@babel/core' | ||
import resolve from 'resolve' | ||
import type { Plugin, PluginOption } from 'vite' | ||
import type { Plugin, PluginOption, ResolvedConfig } from 'vite' | ||
import { | ||
@@ -42,3 +42,2 @@ addRefreshWrapper, | ||
jsxPure?: boolean | ||
/** | ||
@@ -48,6 +47,2 @@ * Babel configuration applied in both dev and prod. | ||
babel?: BabelOptions | ||
/** | ||
* @deprecated Use `babel.parserOpts.plugins` instead | ||
*/ | ||
parserPlugins?: ParserOptions['plugins'] | ||
} | ||
@@ -110,3 +105,3 @@ | ||
babelOptions.parserOpts ||= {} as any | ||
babelOptions.parserOpts.plugins ||= opts.parserPlugins || [] | ||
babelOptions.parserOpts.plugins ||= [] | ||
@@ -161,3 +156,3 @@ // Support patterns like: | ||
const ssr = typeof options === 'boolean' ? options : options?.ssr === true | ||
// File extension could be mocked/overriden in querystring. | ||
// File extension could be mocked/overridden in querystring. | ||
const [filepath, querystring = ''] = id.split('?') | ||
@@ -381,8 +376,1 @@ const [extension = ''] = | ||
} | ||
// overwrite for cjs require('...')() usage | ||
// The following lines are inserted by scripts/patchEsbuildDist.ts, | ||
// this doesn't bundle correctly after esbuild 0.14.4 | ||
// | ||
// module.exports = viteReact | ||
// viteReact['default'] = viteReact |
import type * as babelCore from '@babel/core' | ||
import type { types as t, Visitor } from '@babel/core' | ||
import type { Visitor, types as t } from '@babel/core' | ||
@@ -4,0 +4,0 @@ /** |
@@ -0,3 +1,4 @@ | ||
import * as babel from '@babel/core' | ||
import { describe, expect, it } from 'vitest' | ||
import babelRestoreJSX from './babel-restore-jsx' | ||
import * as babel from '@babel/core' | ||
@@ -4,0 +5,0 @@ function jsx(code: string) { |
@@ -0,7 +1,8 @@ | ||
import * as babel from '@babel/core' | ||
import { describe, expect, it } from 'vitest' | ||
import { restoreJSX } from './restore-jsx' | ||
import * as babel from '@babel/core' | ||
async function jsx(sourceCode: string) { | ||
const [ast] = await restoreJSX(babel, sourceCode, 'test.js') | ||
if (ast === null) { | ||
if (ast == null) { | ||
return ast | ||
@@ -8,0 +9,0 @@ } |
@@ -10,2 +10,14 @@ import type * as babelCore from '@babel/core' | ||
async function getBabelRestoreJSX() { | ||
if (!babelRestoreJSX) | ||
babelRestoreJSX = import('./babel-restore-jsx').then((r) => { | ||
const fn = r.default | ||
if ('default' in fn) | ||
// @ts-expect-error | ||
return fn.default | ||
return fn | ||
}) | ||
return babelRestoreJSX | ||
} | ||
/** Restore JSX from `React.createElement` calls */ | ||
@@ -60,4 +72,2 @@ export async function restoreJSX( | ||
babelRestoreJSX ||= import('./babel-restore-jsx') | ||
const result = await babel.transformAsync(code, { | ||
@@ -72,4 +82,3 @@ babelrc: false, | ||
}, | ||
// @ts-ignore | ||
plugins: [(await babelRestoreJSX).default] | ||
plugins: [await getBabelRestoreJSX()] | ||
}) | ||
@@ -76,0 +85,0 @@ |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
73994
16
1976
9
1
2