@@ -5,7 +5,11 @@ import { parse } from 'acorn';
55import { fileURLToPath } from 'node:url' ;
66
77import { importValidationPlugin } from './plugins/esbuild-import-validation.mjs' ;
8- import { applyTransforms , createStripTransform , transformPipelinePlugin } from './plugins/esbuild-transform-pipeline.mjs' ;
8+ import {
9+ applyTransforms ,
10+ createStripTransform ,
11+ transformPipelinePlugin
12+ } from './plugins/esbuild-transform-pipeline.mjs' ;
913import { getBanner } from './rollup-get-banner.mjs' ;
1014import { revision , version } from './rollup-version-revision.mjs' ;
1115
@@ -69,8 +73,6 @@ const PRUNABLE_IMPORTS = new Set([
6973 'validateUserChunks'
7074] ) ;
7175
72- const toPosix = value => value . split ( path . sep ) . join ( '/' ) ;
73-
7476const compactIndent = code => code . replace ( / ^ + / gm, spaces => spaces . replace ( / { 2 } / g, '\t' ) ) ;
7577
7678const shouldCompactIndent = ( { buildType, sourcemaps } ) => {
@@ -116,22 +118,18 @@ const getImportMetaUrl = (file) => {
116118} ;
117119
118120const getUmdBanner = ( banner ) => {
119- return [
120- banner ,
121- '(function (global, factory) {' ,
122- '\ttypeof exports === \'object\' && typeof module !== \'undefined\' ? factory(exports) :' ,
123- '\ttypeof define === \'function\' && define.amd ? define([\'exports\'], factory) :' ,
124- '\t(global = typeof globalThis !== \'undefined\' ? globalThis : global || self, factory(global.pc = {}));' ,
125- '})(this, (function (exports) { \'use strict\';' ,
126- '\tvar _documentCurrentScript = typeof document !== \'undefined\' ? document.currentScript : null;'
127- ] . join ( '\n' ) ;
121+ return `${ banner }
122+ (function (global, factory) {
123+ \ttypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
124+ \ttypeof define === 'function' && define.amd ? define(['exports'], factory) :
125+ \t(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pc = {}));
126+ })(this, (function (exports) { 'use strict';
127+ \tvar _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;` ;
128128} ;
129129
130130const getUmdFooter = ( ) => {
131- return [
132- 'Object.assign(exports, pc);' ,
133- '}));'
134- ] . join ( '\n' ) ;
131+ return `Object.assign(exports, pc);
132+ }));` ;
135133} ;
136134
137135const getPlugins = ( {
@@ -257,15 +255,6 @@ const watchBundled = async (options, startLog, log) => {
257255 return ctx ;
258256} ;
259257
260- const resolveSource = ( source , importer ) => {
261- if ( ! source . startsWith ( '.' ) ) {
262- return null ;
263- }
264-
265- const resolved = path . resolve ( path . dirname ( importer ) , source ) ;
266- return path . extname ( resolved ) ? resolved : `${ resolved } .js` ;
267- } ;
268-
269258const collectIdentifiers = ( node , used ) => {
270259 if ( ! node || typeof node !== 'object' || node . type === 'ImportDeclaration' ) {
271260 return ;
@@ -328,26 +317,22 @@ const collectImports = (source, file) => {
328317 continue ;
329318 }
330319
331- const resolved = resolveSource ( name , file ) ;
332- if ( resolved ) {
333- imports . push ( resolved ) ;
320+ if ( name . startsWith ( '.' ) ) {
321+ const resolved = path . resolve ( path . dirname ( file ) , name ) ;
322+ imports . push ( path . extname ( resolved ) ? resolved : ` ${ resolved } .js` ) ;
334323 }
335324 }
336325
337326 return imports . sort ( ) ;
338327} ;
339328
340- const sameImports = ( a , b ) => {
341- return a . length === b . length && a . every ( ( value , i ) => value === b [ i ] ) ;
342- } ;
343-
344329const rewriteFflate = ( source , file , input ) => {
345330 if ( ! source . includes ( `from '${ FFLATE } '` ) && ! source . includes ( `from "${ FFLATE } "` ) ) {
346331 return source ;
347332 }
348333
349334 const root = path . dirname ( path . resolve ( input ) ) ;
350- const rel = toPosix ( path . relative ( path . dirname ( file ) , root ) ) ;
335+ const rel = path . relative ( path . dirname ( file ) , root ) . split ( path . sep ) . join ( '/' ) ;
351336 const modulePath = path . posix . join ( rel , '..' , 'modules' , FFLATE , 'esm' , 'browser.js' ) ;
352337
353338 return source . replace ( / f r o m [ ' " ] f f l a t e [ ' " ] / g, `from '${ modulePath } '` ) ;
@@ -551,7 +536,10 @@ const watchUnbundled = async (options, startLog, log) => {
551536
552537 const next = await transformFile ( file , ctx ) ;
553538 const prev = graph . get ( file ) ;
554- if ( ! sameImports ( prev . imports , next . imports ) ) {
539+ if (
540+ prev . imports . length !== next . imports . length ||
541+ ! prev . imports . every ( ( value , i ) => value === next . imports [ i ] )
542+ ) {
555543 await fullBuild ( ) ;
556544 return ;
557545 }
0 commit comments