Adding sourceMap flag to extension cli to enable debugging (#9932)

This commit is contained in:
John Huffsmith
2021-11-22 11:48:03 -05:00
committed by GitHub
parent ff002443f0
commit 37dc1d44b1
2 changed files with 18 additions and 7 deletions

View File

@@ -26,7 +26,15 @@ import { getLanguageFromPath, isLanguage } from '../utils/languages';
import { Language } from '../types';
import loadConfig from '../utils/load-config';
type BuildOptions = { type: string; input: string; output: string; language: string; force: boolean; watch: boolean };
type BuildOptions = {
type: string;
input: string;
output: string;
language: string;
force: boolean;
watch: boolean;
sourceMaps: boolean;
};
export default async function build(options: BuildOptions): Promise<void> {
const packagePath = path.resolve('package.json');
@@ -79,8 +87,8 @@ export default async function build(options: BuildOptions): Promise<void> {
const spinner = ora('Building Directus extension...').start();
const rollupOptions = getRollupOptions(type, language, input, config.plugins);
const rollupOutputOptions = getRollupOutputOptions(type, output);
const rollupOptions = getRollupOptions(type, language, input, config.plugins, options);
const rollupOutputOptions = getRollupOutputOptions(type, output, options);
if (options.watch) {
const watcher = rollupWatch({
@@ -127,7 +135,8 @@ function getRollupOptions(
type: ExtensionType,
language: Language,
input: string,
plugins: Plugin[] = []
plugins: Plugin[] = [],
options: BuildOptions
): RollupOptions {
if (isAppExtension(type)) {
return {
@@ -147,7 +156,7 @@ function getRollupOptions(
},
preventAssignment: true,
}),
terser(),
options.sourceMaps ? null : terser(),
],
};
} else {
@@ -166,13 +175,13 @@ function getRollupOptions(
},
preventAssignment: true,
}),
terser(),
options.sourceMaps ? null : terser(),
],
};
}
}
function getRollupOutputOptions(type: ExtensionType, output: string): RollupOutputOptions {
function getRollupOutputOptions(type: ExtensionType, output: string, options: BuildOptions): RollupOutputOptions {
if (isAppExtension(type)) {
return {
file: output,
@@ -183,6 +192,7 @@ function getRollupOutputOptions(type: ExtensionType, output: string): RollupOutp
file: output,
format: 'cjs',
exports: 'default',
sourcemap: options.sourceMaps,
};
}
}

View File

@@ -25,6 +25,7 @@ program
.option('-l, --language <language>', 'overwrite the language to use')
.option('-f, --force', 'ignore the package manifest')
.option('-w, --watch', 'watch and rebuild on changes')
.option('-m --sourceMaps', 'include source maps in output')
.action(build);
program.parse(process.argv);