typescript – Is there any of way of avoid creating of the Node.js developing package local repository cache containing @types and else basic definitions?

I’m writing the TypeScript simplest modules to learn some of the basics of the language, therefore I need TO NOT store (4500 file items within 140MB space) • to at least 100 exercises.
To be fair, these modules be related to Obsidian app Plugin API, hence TypeScript and the transpiler esbuild are needed.

package.json file contents:

{
      "name": "oppa01",
      "main": "oppa01.ts",
      "version": "0.0.1",
      "type": "module",
      "scripts": {
            "version": "zsh version.sh",
            "manual": "esbuild ${name}.ts --bundle --outfile=${name}.js",
            "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
            "watch": "node esbuild.config.mjs",
            "run": "node ${name}.js"
      },
      "keywords": [],
      "author": "canic",
      "license": "MIT",
      "devDependencies": {
            "@types/node": "^16.11.6",
            "@typescript-eslint/eslint-plugin": "5.29.0",
            "@typescript-eslint/parser": "5.29.0",
            "builtin-modules": "3.3.0",
            "esbuild": "0.17.3",
            "tslib": "2.4.0",
            "typescript": "^4.7.4"
      }
}

esbuild.config.mjs contents:

import { esbuild } from 'esbuild';
import { process } from 'process';
import { builtins } from 'builtin-modules';


const banner =
`/*
THIS IS A GENERATED / BUNDLED FILE BY ESBUILD
to view the source, please visit the github repository containing the TypeScript file for 'oppa01 exercise'
*/
`;


const prod = (process.argv[2] === "production");


const context = await esbuild.context ({
    banner: {
        js: banner,
    },
    entryPoints: ["oppa01.ts"],
    bundle: true,
    external: [
        "electron",
        "@codemirror/autocomplete",
        "@codemirror/collab",
        "@codemirror/commands",
        "@codemirror/language",
        "@codemirror/lint",
        "@codemirror/search",
        "@codemirror/state",
        "@codemirror/view",
        "@lezer/common",
        "@lezer/highlight",
        "@lezer/lr",
        ...builtins],
    format: "cjs",
    target: "es2018",
    logLevel: "info",
    sourcemap: prod ? false : "inline",
    treeShaking: true,
    outfile: "oppa01.js",
    minify: false,
});


if (prod) {
  await context.rebuild ();
  process.exit (0);
} else {
    await context.watch ();
}

The GitHub repo: github.com/delayedFromSoft/nodeESBuild

I have tried subpath aliases:

{
      "name": "oppa01",
      "main": "oppa01.ts",
      "version": "0.0.1",
      "imports": {
          "#*": "/usr/local/share/node/node_modules/*"
      },
      ...
}

import { esbuild } from '#/esbuild';
import { process } from '#/process';
import { builtins } from '#/builtin-modules';

Also, require file text inclusion:

// esbuild.config.mjs
import { createRequire } from "module";
const require = createRequire(import.meta.url);
...

Also, --experimental-specifier-resolution=node flag with explicit using and with file name alongside its suffix defining:

import { esbuild } from '#/esbuild/lib/main.js';

Also, absolute path specifying:

// cp -R "$HOME/.nvm/versions/node/v20.18.0/lib/node_modules" /usr/local/share/node
import { esbuild } from '/usr/local/share/node/node_modules/esbuild/lib/main.js';

And also TypeScript compiler typeRoot specifying:

{
  "compilerOptions": {
    "typeRoots": ["/usr/local/share/node/node_modules"]
    ...
  }
}

Read more here: Source link