@naturaldesign/dev 0.0.0-stage → 0.0.12

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/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@naturaldesign/dev",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.12",
4
+ "type": "module",
5
+ "description": "Dev-only plugin for Natural Design: stamps JSX with its source, indexes the project's components and renders them, so Natural Design can show and edit a project's real components. Run `npx @naturaldesign/dev init` in a Next or Vite project.",
6
+ "bin": {
7
+ "naturaldesign-dev": "dist/cli.mjs"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/types/index.d.ts",
12
+ "default": "./dist/index.mjs"
13
+ },
14
+ "./babel": {
15
+ "types": "./dist/types/babel.d.ts",
16
+ "default": "./dist/babel.cjs"
17
+ },
18
+ "./vite": {
19
+ "types": "./dist/types/vite.d.ts",
20
+ "default": "./dist/vite.mjs"
21
+ },
22
+ "./loader": {
23
+ "types": "./dist/types/loader.d.ts",
24
+ "default": "./dist/loader.cjs"
25
+ },
26
+ "./next": {
27
+ "types": "./src/next.d.ts",
28
+ "default": "./src/next.cjs"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "scripts": {
33
+ "build": "bun build src/loader.ts --outfile dist/loader.cjs --target node --format cjs && bun build src/babel.ts --outfile dist/babel.cjs --target node --format cjs && bun build src/vite.ts --outfile dist/vite.mjs --target node --format esm && bun build src/index.ts --outfile dist/index.mjs --target node --format esm && bun build src/cli.ts --outfile dist/cli.mjs --target node --format esm --banner '#!/usr/bin/env node' && chmod +x dist/cli.mjs && tsc src/index.ts src/vite.ts src/babel.ts src/loader.ts --declaration --emitDeclarationOnly --skipLibCheck --module esnext --moduleResolution bundler --target es2022 --types node --outDir dist/types",
34
+ "test": "bun test",
35
+ "pretest": "bun run build",
36
+ "prepublishOnly": "bun run build"
37
+ },
38
+ "dependencies": {
39
+ "@babel/parser": "7.29.2",
40
+ "magic-string": "^0.30.0"
41
+ },
42
+ "devDependencies": {
43
+ "typescript": "^5.6.3"
44
+ },
45
+ "files": [
46
+ "dist",
47
+ "src/next.cjs",
48
+ "src/next.d.ts",
49
+ "README.md",
50
+ "LICENSE"
51
+ ],
52
+ "license": "MIT",
53
+ "keywords": [
54
+ "natural-design",
55
+ "vite-plugin",
56
+ "nextjs",
57
+ "design-tool",
58
+ "components"
59
+ ],
60
+ "engines": {
61
+ "node": ">=18"
62
+ },
63
+ "types": "./dist/types/index.d.ts"
64
+ }
package/src/next.cjs ADDED
@@ -0,0 +1,34 @@
1
+ // Next.js: `import { withNaturalDesign } from '@naturaldesign/dev/next'` then `export default withNaturalDesign(nextConfig, options)`.
2
+ // Adds the loader for webpack and Turbopack in `next dev` only: source, owner and call-site stamps, render-registry
3
+ // registration in 'use client' files, and component descriptors in .next/natural/index/. `options` go to the loader
4
+ // as-is (root, exclude, calls, owners, register, index, indexFolders), so they must stay JSON (Turbopack serialises them).
5
+ // Plain CommonJS so both `require` and ESM named imports work.
6
+ 'use strict'
7
+ const path = require('node:path')
8
+
9
+ function loaderPath() {
10
+ try { return require.resolve('@naturaldesign/dev/loader') } catch { return path.join(__dirname, '..', 'dist', 'loader.cjs') }
11
+ }
12
+
13
+ function withNaturalDesign(config = {}, options = {}) {
14
+ // Production builds carry no stamps: the config goes back untouched.
15
+ if (process.env.NODE_ENV === 'production') return config
16
+ const loader = loaderPath()
17
+ const rule = { test: /\.[jt]sx$/, exclude: /node_modules/, enforce: 'pre', use: [{ loader, options }] }
18
+ const previous = config.webpack
19
+ const turbopackRules = Object.assign({}, (config.turbopack && config.turbopack.rules) || {})
20
+ for (const glob of ['*.tsx', '*.jsx']) if (!turbopackRules[glob]) turbopackRules[glob] = { loaders: [{ loader, options }], as: glob }
21
+ return Object.assign({}, config, {
22
+ turbopack: Object.assign({}, config.turbopack || {}, { rules: turbopackRules }),
23
+ webpack(webpackConfig, context) {
24
+ if (context.dev) {
25
+ webpackConfig.module = webpackConfig.module || {}
26
+ webpackConfig.module.rules = [rule].concat(webpackConfig.module.rules || [])
27
+ }
28
+ return previous ? previous(webpackConfig, context) : webpackConfig
29
+ },
30
+ })
31
+ }
32
+
33
+ module.exports = { withNaturalDesign, default: withNaturalDesign }
34
+ module.exports.withNaturalDesign = withNaturalDesign
package/src/next.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ // Types for `@naturaldesign/dev/next` (next.cjs). The config stays whatever Next config it was given.
2
+ export interface NaturalDesignNextOptions {
3
+ root?: string
4
+ /** Component names that must not receive data-nd-call. */
5
+ exclude?: string[]
6
+ /** Call-site stamps on component elements (default true). */
7
+ calls?: boolean
8
+ /** Owner stamps on host elements (default true). */
9
+ owners?: boolean
10
+ /** Register 'use client' components with the render registry (default true). */
11
+ register?: boolean
12
+ /** Write component descriptors to .next/natural/index (default true). */
13
+ index?: boolean
14
+ /** Folders the index covers, relative to the root. */
15
+ indexFolders?: string[]
16
+ }
17
+ export declare function withNaturalDesign<T extends object>(config?: T, options?: NaturalDesignNextOptions): T
18
+ export default withNaturalDesign