Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 584 Bytes

README.md

File metadata and controls

30 lines (21 loc) · 584 Bytes

tshy-after

Auto set package.json after tshy run

keep types

Set package.types to package.exports['.'].require.types

Auto fix import.meta.url SyntaxError on CJS

SyntaxError: Cannot use 'import.meta' outside a module

e.g.: Get the file's dirname

// src/index.ts

import { fileURLToPath } from 'node:url';
import path from 'node:path';

export function getDirname() {
  if (typeof __dirname !== 'undefined') {
    return __dirname;
  }
  // @ts-ignore
  return path.dirname(fileURLToPath(import.meta.url));
}