@acebuilder/component-tagger 0.0.1 → 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/README.md +49 -0
- package/index.d.ts +30 -4
- package/index.js +25 -36
- package/package.json +26 -4
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @acebuilder/component-tagger
|
|
2
|
+
|
|
3
|
+
Dev-only Next.js loader that injects `data-acebuilder-*` attributes on JSX elements for AceBuilder element selection.
|
|
4
|
+
|
|
5
|
+
Works with **Turbopack** (default `next dev`) and **webpack** (`next dev --webpack`).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add -D @acebuilder/component-tagger
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage (recommended)
|
|
14
|
+
|
|
15
|
+
Wrap your Next config — enables both bundlers:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
// next.config.mjs
|
|
19
|
+
import componentTagger from '@acebuilder/component-tagger'
|
|
20
|
+
|
|
21
|
+
/** @type {import('next').NextConfig} */
|
|
22
|
+
const nextConfig = {}
|
|
23
|
+
|
|
24
|
+
export default componentTagger()(nextConfig)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Turbopack-only
|
|
28
|
+
|
|
29
|
+
If you prefer not to use the wrapper:
|
|
30
|
+
|
|
31
|
+
```js
|
|
32
|
+
import componentTagger from '@acebuilder/component-tagger'
|
|
33
|
+
|
|
34
|
+
export default {
|
|
35
|
+
turbopack: {
|
|
36
|
+
rules: componentTagger.turbopackRules,
|
|
37
|
+
},
|
|
38
|
+
// ...rest of next config
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## AceBuilder sandboxes
|
|
43
|
+
|
|
44
|
+
Platform deploy injects this package automatically:
|
|
45
|
+
|
|
46
|
+
- `package.json` devDependency: `"@acebuilder/component-tagger": "latest"`
|
|
47
|
+
- `next.config` wrapper via AST injection
|
|
48
|
+
|
|
49
|
+
User projects do not need to add it manually.
|
package/index.d.ts
CHANGED
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
import type { NextConfig } from 'next'
|
|
2
2
|
|
|
3
3
|
export interface AceBuilderComponentTaggerOptions {
|
|
4
|
-
/** Test regex for files to process.
|
|
4
|
+
/** Test regex for files to process. Defaults to `/\.((j|t)sx)$/i`. */
|
|
5
5
|
test?: RegExp
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
export interface AceBuilderTurbopackRule {
|
|
9
|
+
loaders: string[]
|
|
10
|
+
as: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type AceBuilderTurbopackRules = Record<string, AceBuilderTurbopackRule>
|
|
14
|
+
|
|
8
15
|
export type WithAceBuilderComponentTagger = (config: NextConfig) => NextConfig
|
|
9
16
|
|
|
10
17
|
/**
|
|
11
|
-
* Next.js plugin
|
|
18
|
+
* Next.js plugin — registers the tagger for Turbopack (default dev) and webpack (`next dev --webpack`).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```js
|
|
22
|
+
* import componentTagger from '@acebuilder/component-tagger'
|
|
23
|
+
* export default componentTagger()(nextConfig)
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* Turbopack-only (manual next.config):
|
|
27
|
+
* ```js
|
|
28
|
+
* import componentTagger from '@acebuilder/component-tagger'
|
|
29
|
+
* export default { turbopack: { rules: componentTagger.turbopackRules }, ...nextConfig }
|
|
30
|
+
* ```
|
|
12
31
|
*/
|
|
13
|
-
declare function withAceBuilderComponentTagger(
|
|
32
|
+
declare function withAceBuilderComponentTagger(
|
|
33
|
+
options?: AceBuilderComponentTaggerOptions,
|
|
34
|
+
): WithAceBuilderComponentTagger
|
|
35
|
+
|
|
36
|
+
declare namespace withAceBuilderComponentTagger {
|
|
37
|
+
/** Turbopack loader rules — fast path without wrapping webpack. */
|
|
38
|
+
const turbopackRules: AceBuilderTurbopackRules
|
|
39
|
+
}
|
|
14
40
|
|
|
15
|
-
export default withAceBuilderComponentTagger
|
|
41
|
+
export default withAceBuilderComponentTagger
|
package/index.js
CHANGED
|
@@ -1,54 +1,42 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Next.js plugin
|
|
4
|
+
* Next.js plugin for AceBuilder component tagging.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* used by AceBuilder for component discovery and visualization.
|
|
6
|
+
* Fast path (recommended): inject `turbopack.rules` in next.config — see
|
|
7
|
+
* `componentTagger.turbopackRules` or sandbox `next-config-inject.ts`.
|
|
9
8
|
*
|
|
10
|
-
*
|
|
11
|
-
* - pluginOptions.test (RegExp): Which files to process. Defaults to `/\.((j|t)sx)$/i`.
|
|
12
|
-
*
|
|
13
|
-
* Usage (CommonJS in next.config.js / next.config.mjs):
|
|
14
|
-
*
|
|
15
|
-
* const withComponentTagger = require('@acebuilder/component-tagger')({
|
|
16
|
-
* // Optionally override which files to process
|
|
17
|
-
* // test: /\.tsx?$/i,
|
|
18
|
-
* })
|
|
19
|
-
*
|
|
20
|
-
* module.exports = withComponentTagger({
|
|
21
|
-
* reactStrictMode: true,
|
|
22
|
-
* // ...any other Next.js config
|
|
23
|
-
* })
|
|
24
|
-
*
|
|
25
|
-
* How it works:
|
|
26
|
-
* - Adds a webpack rule (enforce: 'pre') that applies to files matching `test`, excluding node_modules.
|
|
27
|
-
* - The rule uses the local loader at `./lib/loader`.
|
|
28
|
-
* - If the user already defines a `webpack` function in their Next config, we call it afterwards
|
|
29
|
-
* to preserve user customizations.
|
|
9
|
+
* Legacy path: wrap next.config with this plugin (webpack + turbopack rules).
|
|
30
10
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
11
|
+
const TAGGER_LOADER = require.resolve('./lib/loader')
|
|
12
|
+
|
|
13
|
+
const turbopackRules = {
|
|
14
|
+
'*.{tsx,jsx}': {
|
|
15
|
+
loaders: [TAGGER_LOADER],
|
|
16
|
+
as: '*.js',
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const componentTagger = (pluginOptions = {}) => (inputConfig = {}) => {
|
|
40
21
|
const test = pluginOptions.test || /\.((j|t)sx)$/i
|
|
41
22
|
|
|
42
23
|
/** @type {import('next').NextConfig} */
|
|
43
24
|
const nextConfig = {
|
|
44
25
|
...inputConfig,
|
|
26
|
+
turbopack: {
|
|
27
|
+
...(inputConfig.turbopack || {}),
|
|
28
|
+
rules: {
|
|
29
|
+
...(inputConfig.turbopack?.rules || {}),
|
|
30
|
+
...turbopackRules,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
45
33
|
webpack(config, options) {
|
|
46
34
|
config.module.rules.push({
|
|
47
35
|
test,
|
|
48
36
|
exclude: /node_modules/,
|
|
49
37
|
enforce: 'pre',
|
|
50
38
|
use: {
|
|
51
|
-
loader:
|
|
39
|
+
loader: TAGGER_LOADER,
|
|
52
40
|
},
|
|
53
41
|
})
|
|
54
42
|
if (typeof inputConfig.webpack === 'function') {
|
|
@@ -62,5 +50,6 @@ module.exports = (pluginOptions = {}) => (inputConfig = {}) => {
|
|
|
62
50
|
return nextConfig
|
|
63
51
|
}
|
|
64
52
|
|
|
65
|
-
|
|
66
|
-
module.exports
|
|
53
|
+
componentTagger.turbopackRules = turbopackRules
|
|
54
|
+
module.exports = componentTagger
|
|
55
|
+
module.exports.default = componentTagger
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acebuilder/component-tagger",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Next.js dev loader to tag React components with AceBuilder metadata (Turbopack + webpack).",
|
|
5
6
|
"main": "index.js",
|
|
6
7
|
"types": "index.d.ts",
|
|
7
8
|
"exports": {
|
|
@@ -10,6 +11,11 @@
|
|
|
10
11
|
"require": "./index.js",
|
|
11
12
|
"default": "./index.js",
|
|
12
13
|
"types": "./index.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./lib/loader": {
|
|
16
|
+
"import": "./lib/loader.js",
|
|
17
|
+
"require": "./lib/loader.js",
|
|
18
|
+
"default": "./lib/loader.js"
|
|
13
19
|
}
|
|
14
20
|
},
|
|
15
21
|
"files": [
|
|
@@ -24,13 +30,29 @@
|
|
|
24
30
|
"engines": {
|
|
25
31
|
"node": ">=18"
|
|
26
32
|
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"next": ">=14"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"next": {
|
|
38
|
+
"optional": true
|
|
39
|
+
}
|
|
40
|
+
},
|
|
27
41
|
"keywords": [
|
|
28
|
-
"acebuilder"
|
|
42
|
+
"acebuilder",
|
|
43
|
+
"nextjs",
|
|
44
|
+
"turbopack",
|
|
45
|
+
"webpack",
|
|
46
|
+
"react"
|
|
29
47
|
],
|
|
48
|
+
"license": "MIT",
|
|
49
|
+
"scripts": {
|
|
50
|
+
"publish:package": "npm publish --access public"
|
|
51
|
+
},
|
|
30
52
|
"dependencies": {
|
|
31
53
|
"@babel/parser": "^7.28.4",
|
|
32
54
|
"estree-walker": "2.0.2",
|
|
33
55
|
"magic-string": "^0.30.19",
|
|
34
56
|
"source-map": "^0.7.0"
|
|
35
57
|
}
|
|
36
|
-
}
|
|
58
|
+
}
|