@@ -19,13 +19,14 @@ import babelPluginTransformUnicodeSetsRegex from "@babel/plugin-transform-unicod
1919import babelTraverse from "@babel/traverse"
2020import type { LVal , Program } from "@babel/types"
2121import t from "@babel/types"
22+ import rollupPluginAlias from "@rollup/plugin-alias"
2223import { babel as rollupPluginBabel } from "@rollup/plugin-babel"
2324import rollupPluginCommonJS from "@rollup/plugin-commonjs"
2425import rollupPluginJSON from "@rollup/plugin-json"
2526import rollupPluginNodeResolve from "@rollup/plugin-node-resolve"
2627import type { LaxPartial } from "@samual/lib"
2728import { assert } from "@samual/lib/assert"
28- import { resolve as resolvePath } from "path"
29+ import { relative as getRelativePath } from "path"
2930import prettier from "prettier"
3031import { rollup } from "rollup"
3132import { supportedExtensions as extensions } from "../constants"
@@ -60,6 +61,8 @@ export type ProcessOptions = LaxPartial<{
6061 * when left unset or set to `undefined`, automatically uses or doesn't use quine cheats based on character count
6162 */
6263 forceQuineCheats : boolean
64+
65+ rootFolderPath : string
6366} > & { /** the name of this script (or set to `true` if not yet known) */ scriptName : string | true }
6467
6568/** Minifies a given script
@@ -72,7 +75,8 @@ export async function processScript(code: string, {
7275 scriptName,
7376 filePath,
7477 mangleNames = false ,
75- forceQuineCheats
78+ forceQuineCheats,
79+ rootFolderPath
7680} : ProcessOptions ) : Promise < { script : string , warnings : { message : string } [ ] } > {
7781 assert ( / ^ \w { 11 } $ / . exec ( uniqueId ) , HERE )
7882
@@ -178,7 +182,7 @@ export async function processScript(code: string, {
178182 let filePathResolved
179183
180184 if ( filePath ) {
181- filePathResolved = resolvePath ( filePath )
185+ filePathResolved = getRelativePath ( `.` , filePath )
182186
183187 if ( filePath . endsWith ( `.ts` ) ) {
184188 plugins . push ( [
@@ -249,6 +253,8 @@ export async function processScript(code: string, {
249253 )
250254 }
251255
256+ console . debug ( HERE , extensions )
257+
252258 const bundle = await rollup ( {
253259 input : filePathResolved ,
254260 plugins : [
@@ -289,7 +295,8 @@ export async function processScript(code: string, {
289295 extensions
290296 } ) ,
291297 rollupPluginCommonJS ( ) ,
292- rollupPluginNodeResolve ( { extensions } )
298+ rollupPluginNodeResolve ( { extensions } ) ,
299+ ! ! rootFolderPath && rollupPluginAlias ( { entries : [ { find : / ^ \/ / , replacement : `${ rootFolderPath } /` } ] } )
293300 ] ,
294301 treeshake : { moduleSideEffects : false }
295302 } )
0 commit comments