mattermost/webapp/platform/shared/build/parcel-namer-shared.ts
Harrison Healey 2da1e56e6c
MM-67323 Add system for plugins to use shared package and allow plugins to load asynchronously (#35183)
* Remove jest-junit and unignore build folder in web app packages

We don't actually use the file output by jest-junit, and I don't think we
have since we moved off of Jenkins for CI

* Move parcel-namer-shared into build folder

* MM-67323 Add loadSharedDependency API and script for plugins to use it

* Fix client and mattermost-redux packages missing const enums

* Change interface for webAppExternals
2026-02-17 12:57:49 -05:00

44 lines
1.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import * as path from 'node:path';
import {Namer} from '@parcel/plugin';
import type {FilePath} from '@parcel/types';
/**
* This Namer changes how Parcel outputs its files to put them into subfolders based on where they were originally in
* the source folder.
*
* By default, files output by Parcel are not put into subfolders of dist, and they instead rely on hashes to
* differentiate between them. We want to be able to import those directly, so
*/
export default new Namer({
async name(opts): Promise<FilePath | null | undefined> {
const {bundle} = opts;
const mainEntry = bundle.getMainEntry();
if (!mainEntry) {
return null;
}
// Get the relative file path within the source folder
const relativeDir = path.posix.relative('./src', path.dirname(mainEntry.filePath));
let filename;
if (bundle.type === 'js') {
// Rename generated JS files from FILE.js to FILE.TARGET.js or FILE.TARGET.js to fix naming conflict
// between CommonJS and ESM files
filename = path.basename(mainEntry.filePath, path.extname(mainEntry.filePath));
filename += '.' + bundle.target.name + '.js';
} else if (bundle.type === 'ts') {
filename = path.basename(mainEntry.filePath, path.extname(mainEntry.filePath)) + '.d.ts';
} else {
filename = bundle.target.name + path.extname(mainEntry.filePath);
}
const newPath = path.posix.join(relativeDir, filename);
return newPath;
},
});