egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
8.49k stars 209 forks source link

Cannot Build files on Windows with absolute, or relative paths #1150

Closed Seroxdesign closed 3 days ago

Seroxdesign commented 4 days ago

Our goal:

Problem:

export async function compileWalletSetupFunctions(
  walletSetupDir: string,
  debug: boolean
) {
  const outDir = path.join(ensureCacheDirExists(), OUT_DIR_NAME);

  // Use a normalized glob pattern
  const globPattern = path.join(walletSetupDir, '**', '*.setup.{ts,js,mjs}');

  // Use glob to find files, ensuring proper path handling
  const fileList = await glob(globPattern, { absolute: true, windowsPathsNoEscape: true });

  if (debug) {
    console.log('[DEBUG] Found the following wallet setup files:');
    console.log(fileList, '\n');
  }

  // TODO: This error message is copied over from another function. Refactor this.
  if (!fileList.length) {
    throw new Error(
      [
        `No wallet setup files found at ${walletSetupDir}`,
        'Remember that all wallet setup files must end with `.setup.{ts,js,mjs}` extension!'
      ].join('\n')
    );
  }

  try {
    await build({
      name: 'cli-build',
      silent: true,
      entry: fileList,
      clean: true,
      outDir,
      format: 'esm',
      splitting: true,
      sourcemap: false,
      config: false,
      // TODO: Make this list configurable.
      external: ['@synthetixio/synpress', '@playwright/test', 'playwright-core', 'esbuild', 'tsup'],
      banner: {
        js: FIXES_BANNER
      },
      esbuildOptions(options) {
        // TODO: In this step, if the debug file is present, we should modify `console.log` so it prints from which file the log is coming from.
        // We're dropping `console.log` and `debugger` statements because they do not play nicely with the Playwright Test Runner.
        options.drop = debug ? [] : ['console', 'debugger']
      }
    })
  } catch (e) {
    console.log(e)
  }
  return outDir
}

At my whits end as I've read most of the issues in the repo, maybe I'm missing something super obvious but any help would be appreciated.

Resources:

Seroxdesign commented 3 days ago

Solved using this pattern:

// Credit: https://github.com/rollup/plugins/blob/master/packages/pluginutils/src/normalizePath.ts#L5
const normalizePath = (filename: string) => filename.split(win32.sep).join(posix.sep);

https://github.com/shellscape/jsx-email/pull/44/files