Skip to content

Commit

Permalink
refactor(scripts): identify cts/mts as code modules (#1977)
Browse files Browse the repository at this point in the history
to make it easier to migrate to esm
also picking up cjs/mjs
  • Loading branch information
AviVahl authored Aug 9, 2023
1 parent 590ee98 commit 4021296
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/scripts/src/build-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,23 @@ export const CONFIG_QUERY_PARAM = 'config';
export const FEATURE_QUERY_PARAM = 'feature';

// File naming helpers
export const isCodeModule = (fileName: string) =>
(fileName.endsWith('.ts') && !fileName.endsWith('.d.ts')) || fileName.endsWith('.tsx') || fileName.endsWith('.js');
export function isCodeModule(fileName: string) {
const fileExtension = path.extname(fileName);
switch (fileExtension) {
case '.ts':
case '.mts':
case '.cts':
return path.extname(path.basename(fileName, fileExtension)) !== '.d';
case '.tsx':
case '.js':
case '.mjs':
case '.cjs':
return true;
default:
return false;
}
}

export const isConfigFile = (fileName: string) => fileName.indexOf(CONFIG_FILENAME_HINT) >= 1 && isCodeModule(fileName);
export const isEnvFile = (fileName: string) => fileName.indexOf(ENV_FILENAME_HINT) >= 1 && isCodeModule(fileName);
export const isPreloadFile = (fileName: string) =>
Expand Down

0 comments on commit 4021296

Please sign in to comment.