Skip to content

Commit

Permalink
NPM packaging. Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
mario4tier committed Aug 26, 2024
1 parent de1dbc9 commit a0c4444
Show file tree
Hide file tree
Showing 60 changed files with 6,841 additions and 1,065 deletions.
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
extends: ['turbo', '@solana/eslint-config-solana', '@solana/eslint-config-solana/jest'],
root: true,
rules: {
'jest/expect-expect': [
'error',
{ assertFunctionNames: ['expect', 'expectNewPreOffset', 'expectNewPostOffset'] },
],
},
};
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# File system
.DS_Store
desktop.ini
*.pem

# Thumbnails
._*
Expand Down Expand Up @@ -96,10 +97,15 @@ pip-selfcheck.json

# Node.js
node_modules
.pnp
.pnp.js
.tsbuildinfo
*.tsbuildinfo
.turbo

# Vercel
.vercel

# Test outputs
playwright-report/
playwright/.cache/
Expand All @@ -121,7 +127,7 @@ docs/src/.vuepress/dist/
docs/pnpm-lock.yaml
docs/package.json

# Other package "lock" should *never* be pushed.
# pnpm is used. Other package "lock" should *never* be pushed.
package-lock.json
yarn.lock

Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.template
*.template
dist/
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"singleQuote": true,
"jsxSingleQuote": true
"singleQuote": true,
"jsxSingleQuote": true
}
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "esbenp.prettier-vscode",
"eslint.workingDirectories": [
{
"mode": "auto"
}
]
}
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Suiftly
# Suiftly - CDN Optimizations for Sui Walrus

CDN Optimization for Sui Walrus
Load most Walrus blobs in less than 100 milliseconds!

Have Webapps load your blobs in less than 50 milliseconds!
Works for any Web2/Web3 browser and NodeJS apps.

Project status: **Planning**
Join the discussion on [Discord](https://discord.com/invite/Erb6SwsVbH)

Join the discussion on [Discord](https://discord.com/invite/Erb6SwsVbH)
# Thank you!
- [Mysten Labs](https://mystenlabs.com) and the [Sui foundation](https://sui.io) for their innovations and financial support.
- [kkomelin/sui-dapp-starter](https://github.com/kkomelin/sui-dapp-starter) time saver template
- [Solana](https://github.com/solana-labs/solana-web3.js) inspiring monorepo scoped packages structure, which is mostly re-used for this project.
2 changes: 1 addition & 1 deletion docs/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ icon: home
title: Home
heroImage: /logo.png
heroText: Suiftly
tagline: CDN Optimization for Sui Walrus
tagline: CDN Optimizations for Sui Walrus
actions:
- text: Try it!
link: /demo.md
Expand Down
91 changes: 67 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,69 @@
{
"name": "suiftly.monorepo",
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"test": "jest"
},
"engineStrict": true,
"engines": {
"node": ">=14.0.0",
"npm": "please-use-pnpm",
"pnpm": "^9",
"yarn": "please-use-pnpm"
},
"packageManager": "[email protected]",
"devDependencies": {
"@types/jest": "^29.5.12",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"ts-jest": "^29.2.5",
"tsup": "^8.2.4",
"typescript": "^5.5.4"
}
"name": "suiftly.monorepo",
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"build": "turbo run --concurrency=${TURBO_CONCURRENCY:-95.84%} build",
"compile": "turbo run --concurrency=${TURBO_CONCURRENCY:-95.84%} compile:js compile:typedefs",
"lint": "turbo run --concurrency=${TURBO_CONCURRENCY:-95.84%} test:lint",
"style:fix": "turbo run --concurrency=${TURBO_CONCURRENCY:-95.84%} style:fix && pnpm prettier --log-level warn --ignore-unknown --write '{.,!packages}/*'",
"test": "turbo run --concurrency=${TURBO_CONCURRENCY:-95.84%} test:unit:browser test:unit:node"
},
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.7",
"@solana/eslint-config-solana": "^3.0.4",
"@solana/prettier-config-solana": "0.0.5",
"@suiftly/build-scripts": "workspace:*",
"@suiftly/test-config": "workspace:*",
"@suiftly/test-matchers": "workspace:*",
"@suiftly/tsconfig": "workspace:*",
"@swc/jest": "^0.2.36",
"@types/jest": "^29.5.12",
"@types/node": "^22",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"agadoo": "^3.0.0",
"eslint": "^8.57.0",
"eslint-config-turbo": "^2.0.14",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-typescript-sort-keys": "^3.2.0",
"jest": "^30.0.0-alpha.6",
"jest-environment-jsdom": "^30.0.0-alpha.6",
"jest-runner-eslint": "^2.2.0",
"jest-runner-prettier": "^1.0.0",
"jest-watch-master": "^1.0.0",
"jest-watch-select-projects": "^2.0.0",
"jest-watch-typeahead": "^2.2.2",
"prettier": "^3.3.3",
"ts-node": "^10.9.2",
"tsup": "^8.2.4",
"turbo": "^2.0.14",
"typescript": "^5.5.4"
},
"engineStrict": true,
"engines": {
"node": ">=14.0.0",
"npm": "please-use-pnpm",
"pnpm": "^9",
"yarn": "please-use-pnpm"
},
"packageManager": "[email protected]",
"pnpm": {
"overrides": {
"conventional-changelog-conventionalcommits": ">= 8.0.0",
"jsdom": "^22",
"mock-socket": "^9.3.1",
"shelljs": ">=0.8.5"
},
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
}
},
"prettier": "@solana/prettier-config-solana"
}
3 changes: 3 additions & 0 deletions packages/build-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `build-scripts`

This is the base build script shared across all packages in this monorepo.
42 changes: 42 additions & 0 deletions packages/build-scripts/dev-flag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { readFile } from 'fs/promises';
import jscodeshift from 'jscodeshift';
import { Options } from 'tsup';

type Loader = NonNullable<
NonNullable<Awaited<NonNullable<ReturnType<Parameters<Parameters<Plugin['setup']>[0]['onLoad']>[1]>>>>['loader']
>;
type Plugin = NonNullable<Options['esbuildPlugins']>[number];

function replaceDev(source: string): string {
if (/__DEV__/.test(source) !== true) {
return source;
}
const j = jscodeshift.withParser('tsx');
const root = j(source);
root.find(j.Identifier, { name: '__DEV__' }).replaceWith(() =>
j.binaryExpression(
'!==',
j.memberExpression(
j.memberExpression(j.identifier('process'), j.identifier('env')),
j.identifier('NODE_ENV'),
),
j.stringLiteral('production'),
),
);
return root.toSource();
}

export const DevFlagPlugin: Plugin = {
name: 'dev-flag-plugin',
setup(build) {
build.onLoad({ filter: /\.(t|j)sx?$/, namespace: 'file' }, async ({ path }) => {
const contents = await readFile(path, 'utf-8');
const ext = path.slice(path.lastIndexOf('.') + 1);
const loader = (ext.match(/(j|t)sx?$/) ? ext : 'js') as Loader;
return {
contents: replaceDev(contents),
loader,
};
});
},
};
87 changes: 87 additions & 0 deletions packages/build-scripts/getBaseConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { env } from 'node:process';

import browsersListToEsBuild from 'browserslist-to-esbuild';
import { Format, Options } from 'tsup';

import { DevFlagPlugin } from './dev-flag';

type Platform =
| 'browser'
// React Native
| 'native'
| 'node';

const BROWSERSLIST_TARGETS = browsersListToEsBuild();

export function getBaseConfig(platform: Platform, formats: Format[], _options: Options): Options[] {
return [true, false]
.flatMap<Options | null>(isDebugBuild =>
formats.map(format =>
format !== 'iife' && isDebugBuild
? null // We don't build debug builds for packages; only for the iife bundle.
: {
define: {
__BROWSER__: `${platform === 'browser'}`,
__NODEJS__: `${platform === 'node'}`,
__REACTNATIVE__: `${platform === 'native'}`,
__VERSION__: `"${env.npm_package_version}"`,
},
entry: [`./src/index.ts`],
esbuildOptions(options, context) {
const { format } = context;
options.minify = format === 'iife' && !isDebugBuild;
if (format === 'iife') {
options.define = {
...options.define,
__DEV__: `${isDebugBuild}`,
};
options.target = BROWSERSLIST_TARGETS;
} else {
options.define = {
...options.define,
// Preserve `process.env.NODE_ENV` in the output without
// replacing it. This allows consumers' bundlers to replace it
// as they see fit.
'process.env.NODE_ENV': 'process.env.NODE_ENV',
};
}
},
esbuildPlugins: [DevFlagPlugin],
external: [
// Despite inlining `@solana/text-encoding-impl`, do not recursively inline `fastestsmallesttextencoderdecoder`.
'fastestsmallesttextencoderdecoder',
// Despite inlining `@solana/ws-impl`, do not recursively inline `ws`.
'ws',
],
format,
globalName: 'globalThis.solanaWeb3',
name: platform,
// Inline private, non-published packages.
// WARNING: This inlines packages recursively. Make sure these don't have deep dep trees.
noExternal: [
// @noble/ed25519 is an ESM-only module, so we have to inline it in CJS builds.
...(format === 'cjs' ? ['@noble/ed25519'] : []),
'@solana/crypto-impl',
'@solana/text-encoding-impl',
'@solana/ws-impl',
],
outExtension({ format }) {
let extension;
if (format === 'iife') {
extension = `.${isDebugBuild ? 'development' : 'production.min'}.js`;
} else {
extension = `.${platform}.${format === 'cjs' ? 'cjs' : 'mjs'}`;
}
return {
js: extension,
};
},
platform: platform === 'node' ? 'node' : 'browser',
pure: ['process'],
sourcemap: format !== 'iife' || isDebugBuild,
treeshake: true,
},
),
)
.filter(Boolean) as Options[];
}
14 changes: 14 additions & 0 deletions packages/build-scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@suiftly/build-scripts",
"version": "0.0.0",
"private": true,
"files": [
"tsup.config.library.ts",
"tsup.config.package.ts"
],
"devDependencies": {
"@types/jscodeshift": "^0.11.11",
"browserslist-to-esbuild": "^2.1.1",
"jscodeshift": "^17.0.0"
}
}
8 changes: 8 additions & 0 deletions packages/build-scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"types": ["node"]
},
"display": "Build Scripts",
"extends": "../tsconfig/base.json"
}
5 changes: 5 additions & 0 deletions packages/build-scripts/tsup.config.browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'tsup';

import { getBaseConfig } from './getBaseConfig';

export default defineConfig(options => [...getBaseConfig('browser', ['cjs', 'esm'], options)]);
15 changes: 15 additions & 0 deletions packages/build-scripts/tsup.config.library.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig } from 'tsup';

import { getBaseConfig } from './getBaseConfig';
import packageConfigOrConfigsOrPromiseGetterForSame from './tsup.config.package';

export default defineConfig(async options => {
const packageConfigOptionOrOptions =
typeof packageConfigOrConfigsOrPromiseGetterForSame === 'function'
? await packageConfigOrConfigsOrPromiseGetterForSame(options)
: packageConfigOrConfigsOrPromiseGetterForSame;
const packageConfigOptions = Array.isArray(packageConfigOptionOrOptions)
? packageConfigOptionOrOptions
: [packageConfigOptionOrOptions];
return [...packageConfigOptions, ...getBaseConfig('browser', ['iife'], options)];
});
9 changes: 9 additions & 0 deletions packages/build-scripts/tsup.config.package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'tsup';

import { getBaseConfig } from './getBaseConfig';

export default defineConfig(options => [
...getBaseConfig('node', ['cjs', 'esm'], options),
...getBaseConfig('browser', ['cjs', 'esm'], options),
...getBaseConfig('native', ['esm'], options),
]);
1 change: 1 addition & 0 deletions packages/core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
1 change: 1 addition & 0 deletions packages/core/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
1 change: 1 addition & 0 deletions packages/core/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
4 changes: 4 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

## [0.0.1]-[0.0.x]
- alpha test releases. Do not use.
Loading

0 comments on commit a0c4444

Please sign in to comment.