Skip to content

Commit 40e4a04

Browse files
committed
feat!: remove acorn dependency and require custom parser setup
Users must now call `setParseImpl` to provide custom parsing logic before invoking `this.parse`. Acorn has been removed as a dependency. closes #480
1 parent d153346 commit 40e4a04

File tree

13 files changed

+24
-36
lines changed

13 files changed

+24
-36
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
},
4848
"dependencies": {
4949
"@jridgewell/remapping": "catalog:prod",
50-
"acorn": "catalog:prod",
5150
"picomatch": "catalog:prod",
5251
"webpack-virtual-modules": "catalog:prod"
5352
},

pnpm-lock.yaml

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ catalogs:
5151

5252
prod:
5353
'@jridgewell/remapping': ^2.3.5
54-
acorn: ^8.15.0
5554
picomatch: ^4.0.3
5655
webpack-virtual-modules: ^0.6.2
5756

src/bun/utils.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Loader, PluginBuilder } from 'bun'
22
import type { UnpluginBuildContext, UnpluginContext, UnpluginMessage } from '../types'
33
import fs from 'node:fs'
44
import path from 'node:path'
5-
import * as acorn from 'acorn'
5+
import { parse } from '../utils/parse'
66

77
const ExtToLoader: Record<string, Loader> = {
88
'.js': 'js',
@@ -47,14 +47,7 @@ export function createBuildContext(build: PluginBuilder): UnpluginBuildContext {
4747
fs.writeFileSync(outPath, emittedFile.source)
4848
}
4949
},
50-
parse(code, opts = {}) {
51-
return acorn.parse(code, {
52-
sourceType: 'module',
53-
ecmaVersion: 'latest',
54-
locations: true,
55-
...opts,
56-
})
57-
},
50+
parse,
5851
getNativeBuildContext() {
5952
return { framework: 'bun', build }
6053
},

src/esbuild/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Buffer } from 'node:buffer'
66
import fs from 'node:fs'
77
import path from 'node:path'
88
import remapping from '@jridgewell/remapping'
9-
import { parse } from '../utils/context'
9+
import { parse } from '../utils/parse'
1010

1111
const ExtToLoader: Record<string, Loader> = {
1212
'.js': 'js',

src/farm/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { CompilationContext } from '@farmfe/core'
22
import type { UnpluginBuildContext, UnpluginContext } from '../types'
33
import { Buffer } from 'node:buffer'
44
import { extname } from 'node:path'
5-
import { parse } from '../utils/context'
5+
import { parse } from '../utils/parse'
66

77
export function createFarmContext(
88
context: CompilationContext,

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './define'
22
export * from './types'
3+
export { setParseImpl } from './utils/parse'

src/rspack/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Compilation, Compiler, LoaderContext } from '@rspack/core'
22
import type { UnpluginBuildContext, UnpluginContext, UnpluginMessage } from '../types'
33
import { Buffer } from 'node:buffer'
44
import { resolve } from 'node:path'
5-
import { parse } from '../utils/context'
5+
import { parse } from '../utils/parse'
66

77
export function createBuildContext(compiler: Compiler, compilation: Compilation, loaderContext?: LoaderContext): UnpluginBuildContext {
88
return {

src/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type { CompilationContext as FarmCompilationContext, JsPlugin as FarmPlugin } from '@farmfe/core'
22
import type { Compilation as RspackCompilation, Compiler as RspackCompiler, LoaderContext as RspackLoaderContext, RspackPluginInstance } from '@rspack/core'
3-
import type { Options as AcornOptions } from 'acorn'
43
import type { BunPlugin, PluginBuilder as BunPluginBuilder } from 'bun'
54
import type { BuildOptions, Plugin as EsbuildPlugin, Loader, PluginBuild } from 'esbuild'
65
import type { Plugin as RolldownPlugin } from 'rolldown'
7-
import type { AstNode, EmittedAsset, PluginContextMeta as RollupContextMeta, Plugin as RollupPlugin, SourceMapInput } from 'rollup'
6+
import type { EmittedAsset, PluginContextMeta as RollupContextMeta, Plugin as RollupPlugin, SourceMapInput } from 'rollup'
87
import type { Plugin as UnloaderPlugin } from 'unloader'
98
import type { Plugin as VitePlugin } from 'vite'
109
import type { Compilation as WebpackCompilation, Compiler as WebpackCompiler, LoaderContext as WebpackLoaderContext, WebpackPluginInstance } from 'webpack'
@@ -61,7 +60,7 @@ export interface UnpluginBuildContext {
6160
addWatchFile: (id: string) => void
6261
emitFile: (emittedFile: EmittedAsset) => void
6362
getWatchFiles: () => string[]
64-
parse: (input: string, options?: Partial<AcornOptions>) => AstNode
63+
parse: (input: string, options?: any) => any
6564
getNativeBuildContext?: (() => NativeBuildContext) | undefined
6665
}
6766

src/utils/context.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)