Skip to content

Commit

Permalink
wip: build
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed May 14, 2024
1 parent 37b4800 commit 8d8b81f
Show file tree
Hide file tree
Showing 18 changed files with 249 additions and 1,187 deletions.
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
"engines": {
"node": "^20"
},
"homepage": "https://github.com/foomo/sesamy-ts#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/foomo/sesamy-ts.git"
},
"bugs": {
"url": "https://github.com/foomo/sesamy-ts/issues"
},
"publishConfig": {
"registry":"https://npm.pkg.github.com/"
},
"scripts": {
"build": "turbo run build --cache-dir=.turbo",
"dev": "turbo run dev",
Expand All @@ -15,7 +26,7 @@
"clean": "turbo run clean"
},
"devDependencies": {
"@repo/config-typescript": "workspace:*",
"@repo/typescript-config": "workspace:*",
"biome": "latest",
"turbo": "latest"
},
Expand Down
38 changes: 0 additions & 38 deletions packages/config-typescript/base.json

This file was deleted.

17 changes: 0 additions & 17 deletions packages/config-typescript/library.json

This file was deleted.

21 changes: 0 additions & 21 deletions packages/config-typescript/nextjs.json

This file was deleted.

8 changes: 0 additions & 8 deletions packages/config-typescript/react-jsx-library.json

This file was deleted.

56 changes: 56 additions & 0 deletions packages/sesamy/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { build } from "esbuild";

async function buildAll(): Promise<void> {
await Promise.all([
build({
platform: "node",
format: "esm",
splitting: true,
entryPoints: ["src/index.ts"],
outdir: "dist/node",
bundle: true,
minify: MINIFY,
sourcemap: SOURCEMAP,
banner: esmNodeSupportBanner,
external: ["@opentelemetry/api"],
plugins: [externalCjsToEsmPlugin(peerDependencies)],
}),
build({
target: "esnext",
format: "esm",
splitting: false,
entryPoints: ["src/index.ts"],
outdir: "dist/edge",
bundle: true,
minify: MINIFY,
sourcemap: SOURCEMAP,
banner: edgeSupportBanner,
external: ["@opentelemetry/api"],
plugins: [
externalCjsToEsmPlugin(["async_hooks", "events", ...peerDependencies]),
stripEvalEdge,
],
}),
]);

// Check max size.
const errors: string[] = [];
for (const [file, maxSize] of Object.entries(MAX_SIZES)) {
// eslint-disable-next-line no-await-in-loop
const s = await stat(file);
if (s.size > maxSize) {
errors.push(
`${file}: the size of ${s.size} is over the maximum allowed size of ${maxSize}`
);
}
}
if (errors.length > 0) {
for (const error of errors) {
// eslint-disable-next-line no-console
console.error(error);
}
process.exit(1);
}
}

void buildAll();
23 changes: 13 additions & 10 deletions packages/sesamy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"node": ">=20"
},
"scripts": {
"build": "tsc",
"build": "pnpm clean && pnpm tsx build.ts",
"clean": "rimraf dist",
"type-check": "tsc --noEmit"
},
"files": ["dist"],
Expand Down Expand Up @@ -45,20 +46,22 @@
"default": "./dist/index.node.js"
}
},
"peerDependencies": {
"react": "18.2.0",
"react-dom": "18.2.0"
},
"dependencies": {
},
"dependencies": {},
"devDependencies": {
"@repo/config-typescript": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@types/gtag.js": "0.0.19",
"@types/node": "^20",
"@types/react": "18.2.48",
"@types/react-dom": "18.2.18",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.3.3",
"tsup": "8.0.1"
"typescript": "^5",
"tsx": "latest",
"rimraf": "latest",
"esbuild": "latest"
},
"peerDependencies": {
"react": "18.2.0",
"react-dom": "18.2.0"
}
}
16 changes: 16 additions & 0 deletions packages/sesamy/src/components/GTMScript.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const GTMScript = ({ id }: { id: string }) => {
return (
<script
dangerouslySetInnerHTML={{
__html: `
(function(w,d,s,l,g,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
w[g]=function(){w[l].push(arguments);}
})(window,document,'script','dataLayer','gtag','${id}');
`,
}}
/>
);
};
19 changes: 1 addition & 18 deletions packages/sesamy/src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
import * as React from 'react';

export const GTMScript = ({ id }: { id: string }) => {
return (
<script
dangerouslySetInnerHTML={{
__html: `
(function(w,d,s,l,g,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
w[g]=function(){w[l].push(arguments);}
})(window,document,'script','dataLayer','gtag','${id}');
`,
}}
/>
);
};
export * from './GTMScript'
1 change: 1 addition & 0 deletions packages/sesamy/src/index.edge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Event } from './types';

export * from './components';
export type * from "./types";

// https://developers.google.com/tag-platform/gtagjs/reference
export const collect = (event: Event) => {
Expand Down
1 change: 1 addition & 0 deletions packages/sesamy/src/index.node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Event } from './types';

export * from './components';
export type * from "./types";

// https://developers.google.com/tag-platform/gtagjs/reference
export const collect = (event: Event) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface Event {
name: string;
params: any;
params?: Record<string, any>;
}
11 changes: 7 additions & 4 deletions packages/sesamy/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@repo/config-typescript/react-jsx-library.json",
"extends": "@repo/typescript-config/library-jsx.json",
"compilerOptions": {
"outDir": "./dist"
"outDir": "./dist",
"lib": ["DOM", "ESNext"],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["."],
"exclude": ["dist", "build", "node_modules"]
"exclude": ["node_modules", "dist"]
}
11 changes: 11 additions & 0 deletions packages/typescript-config/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"skipLibCheck": true,
"strict": true
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "React Library",
"display": "JSX Library",
"extends": "./library.json",
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2015"]
"jsx": "react-jsx"
}
}
23 changes: 23 additions & 0 deletions packages/typescript-config/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Library",
"extends": "./base.json",
"compilerOptions": {
"allowJs": true,
"incremental": true,
"lib": ["ESNext"],
"module": "ESNext",
"moduleResolution": "Node",
"noEmit": true,
"strict": true,
"noUncheckedIndexedAccess": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"isolatedModules": true,
"resolveJsonModule": true,
"skipLibCheck": true,
// Node 16 has 100% ES2021 support (https://node.green/#ES2021)
"target": "ES2021"
},
"exclude": ["node_modules", "dist"]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"name": "@repo/config-typescript",
"name": "@repo/typescript-config",
"version": "0.0.0",
"license": "MIT",
"publishConfig": {
Expand Down
Loading

0 comments on commit 8d8b81f

Please sign in to comment.