Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep correct paths for build output even when build is invoked outside of repo root #6589

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions utils/rollup-build-target.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ import { version, revision } from './rollup-version-revision.mjs';
import { getBanner } from './rollup-get-banner.mjs';
import { babelOptions } from './rollup-babel-options.mjs';

import { dirname, resolve as pathResolve } from 'path';
import { fileURLToPath } from 'url';

// Find path to the repo root
// @ts-ignore import.meta not allowed by tsconfig module:es6, but it works
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const rootDir = pathResolve(__dirname, '..');

/** @typedef {import('rollup').RollupOptions} RollupOptions */
/** @typedef {import('rollup').OutputOptions} OutputOptions */
/** @typedef {import('rollup').ModuleFormat} ModuleFormat */
Expand Down Expand Up @@ -192,6 +201,7 @@ function buildTarget({ moduleFormat, buildType, input = 'src/index.js', dir = 'b
sourcemap: bundled && isDebug && 'inline',
name: 'pc',
preserveModules: !bundled,
preserveModulesRoot: !bundled ? rootDir : undefined,
file: bundled ? `${dir}/${OUT_PREFIX[buildType]}${isUMD ? '.js' : '.mjs'}` : undefined,
dir: !bundled ? `${dir}/${OUT_PREFIX[buildType]}` : undefined,
footer: isUMD ? 'this.pcx = pc;' : undefined
Expand Down