Skip to content

Commit

Permalink
Merge branch 'main' into feat/utils/lazy-initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi committed Apr 4, 2024
2 parents 0249b0e + bf075ef commit 72f8320
Show file tree
Hide file tree
Showing 10 changed files with 769 additions and 127 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@
"build:vanilla:utils": "rollup -c --config-vanilla_utils",
"build:react": "rollup -c --config-react --client-only",
"build:react:utils": "rollup -c --config-react_utils --client-only",
"build:experimental": "rollup -c --config-experimental",
"postbuild": "yarn patch-d-ts && yarn copy && yarn patch-ts3.8 && yarn patch-old-ts && yarn patch-esm-ts && yarn patch-readme",
"prettier": "prettier '*.{js,json,md}' '{src,tests,benchmarks,docs}/**/*.{ts,tsx,md,mdx}' --write",
"prettier:ci": "prettier '*.{js,json,md}' '{src,tests,benchmarks,docs}/**/*.{ts,tsx,md,mdx}' --list-different",
"eslint": "eslint --fix --no-eslintrc --c .eslintrc.json '*.{js,json,ts}' '{src,tests,benchmarks}/**/*.{ts,tsx}'",
"eslint:ci": "eslint --no-eslintrc --c .eslintrc.json '*.{js,json,ts}' '{src,tests,benchmarks}/**/*.{ts,tsx}'",
"pretest": "tsc",
"test": "vitest --ui --coverage",
"test:ci": "vitest",
"test:ci": "vitest && USE_STORE2=true vitest",
"patch-d-ts": "node -e \"var {entries}=require('./rollup.config.js');require('shelljs').find('dist/**/*.d.ts').forEach(f=>{entries.forEach(({find,replacement})=>require('shelljs').sed('-i',new RegExp(' from \\''+find.source.slice(0,-1)+'\\';$'),' from \\''+replacement+'\\';',f));require('shelljs').sed('-i',/ from '(\\.[^']+)\\.ts';$/,' from \\'\\$1\\';',f)})\"",
"copy": "shx cp -r dist/src/* dist/esm && shx cp -r dist/src/* dist && shx rm -rf dist/src && shx rm -rf dist/{src,tests} && downlevel-dts dist dist/ts3.8 --to=3.8 && shx cp package.json readme.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.prettier=undefined;\"",
"patch-ts3.8": "node -e \"require('shelljs').find('dist/ts3.8/**/*.d.ts').forEach(f=>require('fs').appendFileSync(f,'declare type Awaited<T> = T extends Promise<infer V> ? V : T;'))\"",
Expand Down
4 changes: 4 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function createESMConfig(input, output, clientOnly) {
'import.meta.env?.MODE':
'(import.meta.env ? import.meta.env.MODE : undefined)',
}),
'import.meta.env?.USE_STORE2': 'false',
delimiters: ['\\b', '\\b(?!(\\.|/))'],
preventAssignment: true,
}),
Expand All @@ -95,6 +96,7 @@ function createCommonJSConfig(input, output, clientOnly) {
resolve({ extensions }),
replace({
'import.meta.env?.MODE': 'process.env.NODE_ENV',
'import.meta.env?.USE_STORE2': 'false',
delimiters: ['\\b', '\\b(?!(\\.|/))'],
preventAssignment: true,
}),
Expand Down Expand Up @@ -132,6 +134,7 @@ function createUMDConfig(input, output, env, clientOnly) {
resolve({ extensions }),
replace({
'import.meta.env?.MODE': JSON.stringify(env),
'import.meta.env?.USE_STORE2': 'false',
delimiters: ['\\b', '\\b(?!(\\.|/))'],
preventAssignment: true,
}),
Expand All @@ -155,6 +158,7 @@ function createSystemConfig(input, output, env, clientOnly) {
resolve({ extensions }),
replace({
'import.meta.env?.MODE': JSON.stringify(env),
'import.meta.env?.USE_STORE2': 'false',
delimiters: ['\\b', '\\b(?!(\\.|/))'],
preventAssignment: true,
}),
Expand Down
11 changes: 11 additions & 0 deletions src/experimental.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export { atom } from './vanilla/atom.ts'
export type { Atom, WritableAtom, PrimitiveAtom } from './vanilla/atom.ts'
export { createStore, getDefaultStore } from './vanilla/store2.ts'
export type {
Getter,
Setter,
ExtractAtomValue,
ExtractAtomArgs,
ExtractAtomResult,
SetStateAction,
} from './vanilla/typeUtils.ts'
1 change: 1 addition & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare interface ImportMeta {
env?: {
MODE: string
USE_STORE2?: string
}
}
14 changes: 13 additions & 1 deletion src/vanilla.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
export { atom } from './vanilla/atom.ts'
export type { Atom, WritableAtom, PrimitiveAtom } from './vanilla/atom.ts'
export { createStore, getDefaultStore } from './vanilla/store.ts'

// export { createStore, getDefaultStore } from './vanilla/store.ts'
import * as store from './vanilla/store.ts'
import * as store2 from './vanilla/store2.ts'
type CreateStore = typeof store.createStore
type GetDefaultStore = typeof store.getDefaultStore
export const createStore: CreateStore = import.meta.env?.USE_STORE2
? store2.createStore
: store.createStore
export const getDefaultStore: GetDefaultStore = import.meta.env?.USE_STORE2
? store2.getDefaultStore
: store.getDefaultStore

export type {
Getter,
Setter,
Expand Down
Loading

0 comments on commit 72f8320

Please sign in to comment.