Skip to content

Commit

Permalink
fix(build): cleanup build artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseVSeb committed Feb 13, 2024
1 parent 5721d7e commit cafb0a6
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
node_modules
dist
build
bin
stats.html
.rollup.cache
*.tgz
2 changes: 0 additions & 2 deletions bin/runtime-env

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
"bin": {
"runtime-env": "bin/runtime-env"
},
"main": "dist/react/index.js",
"typings": "dist/react/index.d.ts",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/*.js*",
"dist/react"
"dist/*.js*"
],
"engines": {
"node": ">=20"
Expand Down Expand Up @@ -60,6 +59,7 @@
"rollup-plugin-analyzer": "^4.0.0",
"rollup-plugin-delete": "^2.0.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-preserve-shebang": "^1.0.1",
"rollup-plugin-version-injector": "^1.3.3",
"rollup-plugin-visualizer": "^5.12.0",
"semantic-release": "^23.0.0",
Expand Down
29 changes: 29 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion release.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const config = {
},
],
["@semantic-release/npm", { tarballDir: "pack" }],
"@semantic-release/git",
["@semantic-release/github", { assets: "pack/*.tgz" }],
"@semantic-release/git",
],
};

Expand Down
33 changes: 27 additions & 6 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,43 @@ import peerDepsExternal from "rollup-plugin-peer-deps-external";
import versionInjector from "rollup-plugin-version-injector";
import { visualizer } from "rollup-plugin-visualizer";
import { optimizeLodashImports } from "@optimize-lodash/rollup-plugin";
import shebang from "rollup-plugin-preserve-shebang";

/** @type {import("rollup").RollupOptions[]} */
const rollupOptions = [
{
input: "src/cli.ts",
output: [{ file: "bin/runtime-env", format: "commonjs" }],
plugins: [
del({ targets: "bin/*" }),
peerDepsExternal(),
optimizeLodashImports(),
resolve({ preferBuiltins: true }),
commonjs(),
versionInjector({ injectInTags: { fileRegexp: /^runtime-env$/ } }),
eslint({ throwOnError: true }),
typescript({
tsconfig: "./tsconfig.json",
}),
terser(),
shebang(),
analyze({
hideDeps: true,
limit: 0,
summaryOnly: true,
}),
visualizer(),
],
},
{
input: Object.fromEntries(
glob
.sync(["src/cli.ts", "src/react/**/*.{js,ts,jsx,tsx}"])
.sync(["src/*.ts"], { ignore: ["src/cli.ts"] })
.map((file) => [
// This remove `src/` as well as the file extension from each
// file, so e.g. src/nested/foo.js becomes nested/foo
path.relative(
"src",
file.slice(0, file.length - path.extname(file).length),
),
// This expands the relative paths to absolute paths, so e.g.
// src/nested/foo becomes /project/src/nested/foo.js
fileURLToPath(new URL(file, import.meta.url)),
]),
),
Expand All @@ -41,7 +62,7 @@ const rollupOptions = [
versionInjector(),
eslint({ throwOnError: true }),
typescript({
tsconfig: "./tsconfig.json",
tsconfig: "./tsconfig.build.json",
}),
terser(),
analyze({
Expand Down
3 changes: 2 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env node
import { program } from "commander";
import { glob } from "glob";
import { pickBy } from "lodash";
import { injectEnvInHtml } from "./injectEnvInHtml";
import { injectEnvInHtml } from "./utils/injectEnvInHtml";

program
.name("runtime-env")
Expand Down
18 changes: 18 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Development helpers for runtime-env-cli in React.JS.
* Environment variables is loaded in `window.env`.
*/

declare global {
interface WindowEnv extends NodeJS.ProcessEnv {}

interface Window {
env: WindowEnv;
}
}

// if not production, use env from node
if (process.env.NODE_ENV !== "production" && typeof window !== "undefined")
window.env = process.env;

export default window.env;
15 changes: 0 additions & 15 deletions src/react/index.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/react/tsconfig.json

This file was deleted.

File renamed without changes.
11 changes: 11 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true
},
"include": [],
"files": ["src/index.ts"]
}
14 changes: 5 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
"rootDir": "./src" /* Specify the root folder within your source files. */,
"moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */,
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
"paths": {
"@/*": ["./src/*"],
"package.json": ["./package.json"],
} /* Specify a set of entries that re-map imports to additional lookup locations. */,
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
Expand All @@ -42,7 +38,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
"resolveJsonModule": true /* Enable importing .json files. */,
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Expand All @@ -52,15 +48,15 @@
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */

/* Emit */
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
"declarationMap": true /* Create sourcemaps for d.ts files. */,
"emitDeclarationOnly": true /* Only output d.ts files and not JavaScript files. */,
// "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
// "declarationMap": true /* Create sourcemaps for d.ts files. */,
// "emitDeclarationOnly": true /* Only output d.ts files and not JavaScript files. */,
// "sourceMap": true /* Create source map files for emitted JavaScript files. */,
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
"noEmit": true /* Disable emitting files from a compilation. */,
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
Expand Down

0 comments on commit cafb0a6

Please sign in to comment.