@hanzo/next 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +111 -0
- package/dist/index.js.map +1 -0
- package/package.json +37 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 hanzo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** The subset of a Next config this package touches. Structural on purpose: it
|
|
2
|
+
* must not pin a `next` version to type-check, and `NextConfig` moves. */
|
|
3
|
+
export type Config = Record<string, unknown>;
|
|
4
|
+
export type Options = {
|
|
5
|
+
/** App root — where node_modules and src live. Almost always `import.meta.dirname`. */
|
|
6
|
+
root: string;
|
|
7
|
+
/**
|
|
8
|
+
* Source aliases. Defaults to the one every Hanzo app uses, `~` → `<root>/src`.
|
|
9
|
+
* Values are resolved against `root`, so pass them relative.
|
|
10
|
+
*/
|
|
11
|
+
alias?: Record<string, string>;
|
|
12
|
+
/**
|
|
13
|
+
* Extra packages to transpile, ON TOP of every discovered `@hanzogui/*` and the
|
|
14
|
+
* `@hanzo/*` packages that ship source. Additive — the discovered set is never
|
|
15
|
+
* replaced, because replacing it is how a satellite goes missing.
|
|
16
|
+
*/
|
|
17
|
+
transpile?: string[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Every installed `@hanzogui/*`, discovered rather than declared. An absent
|
|
21
|
+
* scope is not an error — an app may carry none.
|
|
22
|
+
*/
|
|
23
|
+
export declare function guiPackages(root: string): string[];
|
|
24
|
+
/** The full transpile list for an app: the source packages, every installed gui
|
|
25
|
+
* satellite, and whatever else the app names. Deduped, order-stable. */
|
|
26
|
+
export declare function transpileList(root: string, extra?: string[]): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Wrap an app's own Next config with the shared answers.
|
|
29
|
+
*
|
|
30
|
+
* The app's config WINS on every key it states — this adds, it does not overrule.
|
|
31
|
+
* `webpack` is the one exception and it composes rather than replaces: the shared
|
|
32
|
+
* resolution is applied first, then the app's hook runs on the result, so an app
|
|
33
|
+
* can still reach the config without losing the aliases underneath it.
|
|
34
|
+
*/
|
|
35
|
+
export declare function hanzo(config: Config | undefined, options: Options): Config;
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA4CA;2EAC2E;AAC3E,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE5C,MAAM,MAAM,OAAO,GAAG;IACpB,uFAAuF;IACvF,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB,CAAA;AAiBD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAMlD;AAED;yEACyE;AACzE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,MAAM,EAAO,GAAG,MAAM,EAAE,CAE1E;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,YAAK,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAgCnE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hanzo/next — the Next.js config every Hanzo app shares.
|
|
3
|
+
*
|
|
4
|
+
* import { hanzo } from '@hanzo/next'
|
|
5
|
+
* export default hanzo(myOwnConfig, { root: import.meta.dirname })
|
|
6
|
+
*
|
|
7
|
+
* Not a preference: each item below is a thing that BREAKS, silently, and that
|
|
8
|
+
* every app on this stack hits identically. They were found one at a time, in
|
|
9
|
+
* one app, and re-deriving them per app is how a fleet drifts.
|
|
10
|
+
*
|
|
11
|
+
* WHAT IT ANSWERS
|
|
12
|
+
*
|
|
13
|
+
* 1. TypeScript 7 is a different engine with no JavaScript API. Next derives its
|
|
14
|
+
* bundler aliases by reading tsconfig `paths` THROUGH the installed
|
|
15
|
+
* typescript, so under 7 it reads nothing: every `~/…` import in a tree goes
|
|
16
|
+
* unresolvable at once, while `tsc --noEmit` stays green — tsc resolves paths
|
|
17
|
+
* itself and never asks the bundler. So a green typecheck and a dead build.
|
|
18
|
+
* The alias is declared here instead, where it does not depend on which
|
|
19
|
+
* compiler happens to be installed. (TS7 also REMOVED `baseUrl`, so the
|
|
20
|
+
* tsconfig that used to carry one is now an error.)
|
|
21
|
+
*
|
|
22
|
+
* 2. The typecheck runs the local `tsc` BINARY (`experimental.useTypeScriptCli`,
|
|
23
|
+
* which Next added for exactly this). The default backend calls the API TS7
|
|
24
|
+
* does not publish, so the typecheck goes quietly ABSENT — the build passes by
|
|
25
|
+
* not checking.
|
|
26
|
+
*
|
|
27
|
+
* 3. @hanzo/gui and its `@hanzogui/*` satellites ship ESM/TSX source, so they are
|
|
28
|
+
* transpiled. The list is DISCOVERED from node_modules, never hardcoded: a
|
|
29
|
+
* hardcoded list is wrong the day a satellite is added, and wrong quietly.
|
|
30
|
+
*
|
|
31
|
+
* 4. `react-native` means `react-native-web` on the web — EXACT match only, so a
|
|
32
|
+
* deep `react-native/Libraries/*` import still finds the real package, which
|
|
33
|
+
* is what its own `.web.js` files expect.
|
|
34
|
+
*
|
|
35
|
+
* A NOTE ON TURBOPACK. Next 16 defaults to it and these apps cannot use it yet:
|
|
36
|
+
* react-native-svg imports `TurboModuleRegistry` from `react-native`, which
|
|
37
|
+
* react-native-web does not export, and the alias that makes RN mean RNW is what
|
|
38
|
+
* surfaces it. That is a gap in the dependency, not a config mistake. So NAME the
|
|
39
|
+
* bundler at the call site (`next build --webpack`) rather than inheriting it —
|
|
40
|
+
* an inherited default is how this arrives as a CI failure instead of a decision.
|
|
41
|
+
*/
|
|
42
|
+
import { readdirSync } from 'node:fs';
|
|
43
|
+
import { join, resolve } from 'node:path';
|
|
44
|
+
/** Packages that ship ESM/TSX SOURCE rather than compiled dist, so a host must
|
|
45
|
+
* transpile them. Kept here so one list serves the fleet. */
|
|
46
|
+
const SOURCE_PACKAGES = [
|
|
47
|
+
'@hanzo/gui',
|
|
48
|
+
'@hanzo/ui',
|
|
49
|
+
'@hanzo/data',
|
|
50
|
+
'@hanzo/dash',
|
|
51
|
+
'@hanzo/canvas',
|
|
52
|
+
'@hanzo/usage',
|
|
53
|
+
'react-native-web',
|
|
54
|
+
];
|
|
55
|
+
/** Web builds prefer a `.web.*` implementation of a module. */
|
|
56
|
+
const WEB_FIRST = ['.web.tsx', '.web.ts', '.web.jsx', '.web.js'];
|
|
57
|
+
/**
|
|
58
|
+
* Every installed `@hanzogui/*`, discovered rather than declared. An absent
|
|
59
|
+
* scope is not an error — an app may carry none.
|
|
60
|
+
*/
|
|
61
|
+
export function guiPackages(root) {
|
|
62
|
+
try {
|
|
63
|
+
return readdirSync(join(root, 'node_modules', '@hanzogui')).map((n) => `@hanzogui/${n}`);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** The full transpile list for an app: the source packages, every installed gui
|
|
70
|
+
* satellite, and whatever else the app names. Deduped, order-stable. */
|
|
71
|
+
export function transpileList(root, extra = []) {
|
|
72
|
+
return [...new Set([...SOURCE_PACKAGES, ...guiPackages(root), ...extra])];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Wrap an app's own Next config with the shared answers.
|
|
76
|
+
*
|
|
77
|
+
* The app's config WINS on every key it states — this adds, it does not overrule.
|
|
78
|
+
* `webpack` is the one exception and it composes rather than replaces: the shared
|
|
79
|
+
* resolution is applied first, then the app's hook runs on the result, so an app
|
|
80
|
+
* can still reach the config without losing the aliases underneath it.
|
|
81
|
+
*/
|
|
82
|
+
export function hanzo(config = {}, options) {
|
|
83
|
+
const { root, alias = { '~': './src' }, transpile = [] } = options;
|
|
84
|
+
const appWebpack = config.webpack;
|
|
85
|
+
const aliases = Object.fromEntries(Object.entries(alias).map(([from, to]) => [from, resolve(root, to)]));
|
|
86
|
+
return {
|
|
87
|
+
...config,
|
|
88
|
+
transpilePackages: transpileList(root, [
|
|
89
|
+
...transpile,
|
|
90
|
+
...(config.transpilePackages ?? []),
|
|
91
|
+
]),
|
|
92
|
+
experimental: {
|
|
93
|
+
esmExternals: true,
|
|
94
|
+
// Run the local tsc BINARY. See (2) above: the default backend reads an
|
|
95
|
+
// API TypeScript 7 does not publish, and a typecheck that silently does
|
|
96
|
+
// not run is worse than one that fails.
|
|
97
|
+
useTypeScriptCli: true,
|
|
98
|
+
...(config.experimental ?? {}),
|
|
99
|
+
},
|
|
100
|
+
webpack(c, ctx) {
|
|
101
|
+
c.resolve.alias = { ...c.resolve.alias, ...aliases, 'react-native$': 'react-native-web' };
|
|
102
|
+
// Keep symlinked paths. A workspace-linked package resolved to its realpath
|
|
103
|
+
// walks up into ITS OWN node_modules and loads a second copy of the gui
|
|
104
|
+
// runtime — two copies, and React context identity dies at the boundary.
|
|
105
|
+
c.resolve.symlinks = false;
|
|
106
|
+
c.resolve.extensions = [...WEB_FIRST, ...c.resolve.extensions];
|
|
107
|
+
return appWebpack ? appWebpack(c, ctx) : c;
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACrC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAsBzC;8DAC8D;AAC9D,MAAM,eAAe,GAAG;IACtB,YAAY;IACZ,WAAW;IACX,aAAa;IACb,aAAa;IACb,eAAe;IACf,cAAc;IACd,kBAAkB;CACnB,CAAA;AAED,+DAA+D;AAC/D,MAAM,SAAS,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,CAAC,CAAA;AAEhE;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,IAAI,CAAC;QACH,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,E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,CAAM,EAAE,GAAQ;YACtB,CAAC,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAA;YACzF,4EAA4E;YAC5E,wEAAwE;YACxE,yEAAyE;YACzE,CAAC,CAAC,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAA;YAC1B,CAAC,CAAC,OAAO,CAAC,UAAU,GAAG,CAAC,GAAG,SAAS,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;YAC9D,OAAO,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC5C,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hanzo/next",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The Next.js config every Hanzo app shares — one runtime, one compiler, one way.",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"next": ">=16"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"typescript": "^7.0.2",
|
|
23
|
+
"vitest": "^3.2.4"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/hanzoai/ui.git",
|
|
31
|
+
"directory": "pkgs/next"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.json",
|
|
35
|
+
"test": "vitest run"
|
|
36
|
+
}
|
|
37
|
+
}
|