@rngpui/craby-devkit 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Geunhyeok LEE
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/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # @rngpui/craby-devkit
2
+
3
+ Development kit for Craby
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @rngpui/craby-devkit
9
+ # or
10
+ pnpm add @rngpui/craby-devkit
11
+ # or
12
+ yarn add @rngpui/craby-devkit
13
+ ```
14
+
15
+ ## Example
16
+
17
+ ### React Native
18
+
19
+ ```js
20
+ // react-native.config.js
21
+ const path = require('node:path');
22
+ const { withWorkspaceModule } = require('@rngpui/craby-devkit');
23
+
24
+ const modulePackagePath = path.resolve(__dirname, '../craby-test');
25
+ const config = {};
26
+
27
+ module.exports = withWorkspaceModule(config, modulePackagePath);
28
+ ```
29
+
30
+ ### Metro
31
+
32
+ ```js
33
+ // metro.config.js
34
+ const { getMetroConfig } = require('@rngpui/craby-devkit');
35
+ const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
36
+
37
+ /**
38
+ * Metro configuration
39
+ * https://reactnative.dev/docs/metro
40
+ *
41
+ * @type {import('metro-config').MetroConfig}
42
+ */
43
+ const config = getMetroConfig(__dirname);
44
+
45
+ module.exports = mergeConfig(getDefaultConfig(__dirname), config);
46
+ ```
47
+
48
+ Visit [https://craby.rs](https://craby.rs) for full documentation.
49
+
50
+ ## License
51
+
52
+ [MIT](LICENSE)
package/dist/index.cjs ADDED
@@ -0,0 +1,138 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+ let node_fs = require("node:fs");
29
+ node_fs = __toESM(node_fs);
30
+ let node_path = require("node:path");
31
+ node_path = __toESM(node_path);
32
+ let oxc_resolver = require("oxc-resolver");
33
+
34
+ //#region src/utils.ts
35
+ function getWorkspaceRoot(rootDir) {
36
+ while (node_path.default.dirname(rootDir) !== rootDir) {
37
+ const packageJsonPath = node_path.default.join(rootDir, "package.json");
38
+ if (node_fs.default.existsSync(packageJsonPath)) {
39
+ const rawPackageJson = node_fs.default.readFileSync(packageJsonPath, "utf8");
40
+ const packageJson = JSON.parse(rawPackageJson);
41
+ if (Array.isArray(packageJson.workspaces)) return rootDir;
42
+ }
43
+ rootDir = node_path.default.dirname(rootDir);
44
+ }
45
+ return null;
46
+ }
47
+
48
+ //#endregion
49
+ //#region src/metro/resolver.ts
50
+ const DEFAULT_ROOT_MODULES = ["react", "react-native"];
51
+ const resolvers = /* @__PURE__ */ new Map();
52
+ function createResolver(options) {
53
+ function createResolverImpl(context, platform, rootPath) {
54
+ const rootModules = options.rootModules ?? DEFAULT_ROOT_MODULES;
55
+ const baseExtensions = context.sourceExts.map((extension) => `.${extension}`);
56
+ let finalExtensions = [...baseExtensions];
57
+ if (context.preferNativePlatform) finalExtensions = [...baseExtensions.map((extension) => `.native${extension}`), ...finalExtensions];
58
+ if (platform) finalExtensions = [...baseExtensions.map((extension) => `.${platform}${extension}`), ...finalExtensions];
59
+ const resolver = new oxc_resolver.ResolverFactory({
60
+ extensions: finalExtensions,
61
+ conditionNames: [
62
+ "react-native",
63
+ "require",
64
+ "node",
65
+ "default"
66
+ ],
67
+ mainFields: [
68
+ "react-native",
69
+ "browser",
70
+ "main"
71
+ ]
72
+ });
73
+ function resolveSync(resolveDir, request) {
74
+ const resolved = resolver.sync(resolveDir, request);
75
+ if (resolved.path == null) throw new Error(`Failed to resolve '${request}' from '${resolveDir}'`);
76
+ return resolved.path;
77
+ }
78
+ function resolve(context$1, request) {
79
+ for (const target of rootModules) if (request === target || request.startsWith(`${target}/`)) return {
80
+ type: "sourceFile",
81
+ filePath: resolveSync(rootPath, request)
82
+ };
83
+ return {
84
+ type: "sourceFile",
85
+ filePath: resolveSync(node_path.default.dirname(context$1.originModulePath), request)
86
+ };
87
+ }
88
+ return resolve;
89
+ }
90
+ return function resolve(context, request, platform) {
91
+ let resolver = resolvers.get(platform);
92
+ if (resolver == null) {
93
+ resolver = createResolverImpl(context, platform, options.rootPath);
94
+ resolvers.set(platform, resolver);
95
+ }
96
+ return resolver(context, request, platform);
97
+ };
98
+ }
99
+
100
+ //#endregion
101
+ //#region src/metro/config.ts
102
+ function getMetroConfig(rootDir, options) {
103
+ return {
104
+ projectRoot: rootDir,
105
+ watchFolders: [getWorkspaceRoot(rootDir)],
106
+ resolver: {
107
+ sourceExts: [
108
+ "ts",
109
+ "tsx",
110
+ "js",
111
+ "jsx",
112
+ "json"
113
+ ],
114
+ resolveRequest: createResolver({
115
+ rootPath: rootDir,
116
+ ...options?.resolverOptions
117
+ })
118
+ }
119
+ };
120
+ }
121
+
122
+ //#endregion
123
+ //#region src/react-native/config.ts
124
+ function withWorkspaceModule(config, modulePackagePath) {
125
+ const rawPackageJson = node_fs.default.readFileSync(node_path.default.join(modulePackagePath, "package.json"), "utf8");
126
+ const name = JSON.parse(rawPackageJson).name;
127
+ return {
128
+ ...config,
129
+ dependencies: {
130
+ ...config.dependencies,
131
+ [name]: { root: modulePackagePath }
132
+ }
133
+ };
134
+ }
135
+
136
+ //#endregion
137
+ exports.getMetroConfig = getMetroConfig;
138
+ exports.withWorkspaceModule = withWorkspaceModule;
@@ -0,0 +1,43 @@
1
+ //#region src/metro/resolver.d.ts
2
+ interface CreateResolverOptions {
3
+ rootPath: string;
4
+ rootModules?: string[];
5
+ }
6
+ /**
7
+ * @see https://github.com/facebook/metro/blob/v0.83.3/packages/metro-resolver/types/types.d.ts#L195-L199
8
+ */
9
+ type CustomResolver = (context: CustomResolutionContext, moduleName: string, platform: string | null) => Resolution;
10
+ type SourceFileResolution = Readonly<{
11
+ type: 'sourceFile';
12
+ filePath: string;
13
+ }>;
14
+ type AssetFileResolution = ReadonlyArray<string>;
15
+ type AssetResolution = Readonly<{
16
+ type: 'assetFiles';
17
+ filePaths: AssetFileResolution;
18
+ }>;
19
+ type Resolution = AssetResolution | SourceFileResolution;
20
+ interface CustomResolutionContext {
21
+ sourceExts: string[];
22
+ originModulePath: string;
23
+ preferNativePlatform?: boolean;
24
+ }
25
+ //#endregion
26
+ //#region src/metro/config.d.ts
27
+ interface GetMetroConfigOptions {
28
+ resolverOptions?: Omit<CreateResolverOptions, 'rootPath'>;
29
+ }
30
+ declare function getMetroConfig(rootDir: string, options: GetMetroConfigOptions): {
31
+ projectRoot: string;
32
+ watchFolders: (string | null)[];
33
+ resolver: {
34
+ sourceExts: string[];
35
+ resolveRequest: CustomResolver;
36
+ };
37
+ };
38
+ //#endregion
39
+ //#region src/react-native/config.d.ts
40
+ type ReactNativeConfig = any;
41
+ declare function withWorkspaceModule(config: ReactNativeConfig, modulePackagePath: string): any;
42
+ //#endregion
43
+ export { getMetroConfig, withWorkspaceModule };
@@ -0,0 +1,43 @@
1
+ //#region src/metro/resolver.d.ts
2
+ interface CreateResolverOptions {
3
+ rootPath: string;
4
+ rootModules?: string[];
5
+ }
6
+ /**
7
+ * @see https://github.com/facebook/metro/blob/v0.83.3/packages/metro-resolver/types/types.d.ts#L195-L199
8
+ */
9
+ type CustomResolver = (context: CustomResolutionContext, moduleName: string, platform: string | null) => Resolution;
10
+ type SourceFileResolution = Readonly<{
11
+ type: 'sourceFile';
12
+ filePath: string;
13
+ }>;
14
+ type AssetFileResolution = ReadonlyArray<string>;
15
+ type AssetResolution = Readonly<{
16
+ type: 'assetFiles';
17
+ filePaths: AssetFileResolution;
18
+ }>;
19
+ type Resolution = AssetResolution | SourceFileResolution;
20
+ interface CustomResolutionContext {
21
+ sourceExts: string[];
22
+ originModulePath: string;
23
+ preferNativePlatform?: boolean;
24
+ }
25
+ //#endregion
26
+ //#region src/metro/config.d.ts
27
+ interface GetMetroConfigOptions {
28
+ resolverOptions?: Omit<CreateResolverOptions, 'rootPath'>;
29
+ }
30
+ declare function getMetroConfig(rootDir: string, options: GetMetroConfigOptions): {
31
+ projectRoot: string;
32
+ watchFolders: (string | null)[];
33
+ resolver: {
34
+ sourceExts: string[];
35
+ resolveRequest: CustomResolver;
36
+ };
37
+ };
38
+ //#endregion
39
+ //#region src/react-native/config.d.ts
40
+ type ReactNativeConfig = any;
41
+ declare function withWorkspaceModule(config: ReactNativeConfig, modulePackagePath: string): any;
42
+ //#endregion
43
+ export { getMetroConfig, withWorkspaceModule };
package/dist/index.js ADDED
@@ -0,0 +1,108 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { ResolverFactory } from "oxc-resolver";
4
+
5
+ //#region src/utils.ts
6
+ function getWorkspaceRoot(rootDir) {
7
+ while (path.dirname(rootDir) !== rootDir) {
8
+ const packageJsonPath = path.join(rootDir, "package.json");
9
+ if (fs.existsSync(packageJsonPath)) {
10
+ const rawPackageJson = fs.readFileSync(packageJsonPath, "utf8");
11
+ const packageJson = JSON.parse(rawPackageJson);
12
+ if (Array.isArray(packageJson.workspaces)) return rootDir;
13
+ }
14
+ rootDir = path.dirname(rootDir);
15
+ }
16
+ return null;
17
+ }
18
+
19
+ //#endregion
20
+ //#region src/metro/resolver.ts
21
+ const DEFAULT_ROOT_MODULES = ["react", "react-native"];
22
+ const resolvers = /* @__PURE__ */ new Map();
23
+ function createResolver(options) {
24
+ function createResolverImpl(context, platform, rootPath) {
25
+ const rootModules = options.rootModules ?? DEFAULT_ROOT_MODULES;
26
+ const baseExtensions = context.sourceExts.map((extension) => `.${extension}`);
27
+ let finalExtensions = [...baseExtensions];
28
+ if (context.preferNativePlatform) finalExtensions = [...baseExtensions.map((extension) => `.native${extension}`), ...finalExtensions];
29
+ if (platform) finalExtensions = [...baseExtensions.map((extension) => `.${platform}${extension}`), ...finalExtensions];
30
+ const resolver = new ResolverFactory({
31
+ extensions: finalExtensions,
32
+ conditionNames: [
33
+ "react-native",
34
+ "require",
35
+ "node",
36
+ "default"
37
+ ],
38
+ mainFields: [
39
+ "react-native",
40
+ "browser",
41
+ "main"
42
+ ]
43
+ });
44
+ function resolveSync(resolveDir, request) {
45
+ const resolved = resolver.sync(resolveDir, request);
46
+ if (resolved.path == null) throw new Error(`Failed to resolve '${request}' from '${resolveDir}'`);
47
+ return resolved.path;
48
+ }
49
+ function resolve(context$1, request) {
50
+ for (const target of rootModules) if (request === target || request.startsWith(`${target}/`)) return {
51
+ type: "sourceFile",
52
+ filePath: resolveSync(rootPath, request)
53
+ };
54
+ return {
55
+ type: "sourceFile",
56
+ filePath: resolveSync(path.dirname(context$1.originModulePath), request)
57
+ };
58
+ }
59
+ return resolve;
60
+ }
61
+ return function resolve(context, request, platform) {
62
+ let resolver = resolvers.get(platform);
63
+ if (resolver == null) {
64
+ resolver = createResolverImpl(context, platform, options.rootPath);
65
+ resolvers.set(platform, resolver);
66
+ }
67
+ return resolver(context, request, platform);
68
+ };
69
+ }
70
+
71
+ //#endregion
72
+ //#region src/metro/config.ts
73
+ function getMetroConfig(rootDir, options) {
74
+ return {
75
+ projectRoot: rootDir,
76
+ watchFolders: [getWorkspaceRoot(rootDir)],
77
+ resolver: {
78
+ sourceExts: [
79
+ "ts",
80
+ "tsx",
81
+ "js",
82
+ "jsx",
83
+ "json"
84
+ ],
85
+ resolveRequest: createResolver({
86
+ rootPath: rootDir,
87
+ ...options?.resolverOptions
88
+ })
89
+ }
90
+ };
91
+ }
92
+
93
+ //#endregion
94
+ //#region src/react-native/config.ts
95
+ function withWorkspaceModule(config, modulePackagePath) {
96
+ const rawPackageJson = fs.readFileSync(path.join(modulePackagePath, "package.json"), "utf8");
97
+ const name = JSON.parse(rawPackageJson).name;
98
+ return {
99
+ ...config,
100
+ dependencies: {
101
+ ...config.dependencies,
102
+ [name]: { root: modulePackagePath }
103
+ }
104
+ };
105
+ }
106
+
107
+ //#endregion
108
+ export { getMetroConfig, withWorkspaceModule };
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@rngpui/craby-devkit",
3
+ "version": "0.1.0",
4
+ "description": "Development kit for Craby",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "scripts": {
23
+ "prepack": "yarn build",
24
+ "typecheck": "tsc --noEmit",
25
+ "build": "tsdown"
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/rngpui/craby.git",
33
+ "directory": "packages/craby-devkit"
34
+ },
35
+ "author": "leegeunhyeok <dev.ghlee@gmail.com> (https://github.com/leegeunhyeok)",
36
+ "license": "MIT",
37
+ "bugs": {
38
+ "url": "https://github.com/rngpui/craby/issues"
39
+ },
40
+ "homepage": "https://github.com/rngpui/craby#readme",
41
+ "dependencies": {
42
+ "oxc-resolver": "^11.11.1"
43
+ },
44
+ "devDependencies": {
45
+ "tsdown": "^0.17.0-beta.4",
46
+ "typescript": "^5.9.3"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ }
51
+ }