@acebuilder/component-tagger 0.1.0 → 0.1.2
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 +12 -18
- package/index.d.ts +2 -25
- package/index.js +2 -19
- package/lib/loader.js +10 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Dev-only Next.js loader that injects `data-acebuilder-*` attributes on JSX elements for AceBuilder element selection.
|
|
4
4
|
|
|
5
|
-
Works with **Turbopack** (default `next dev`) and **webpack** (`next dev --webpack`).
|
|
6
|
-
|
|
7
5
|
## Install
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
8
|
pnpm add -D @acebuilder/component-tagger
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
## Usage
|
|
11
|
+
## Usage
|
|
14
12
|
|
|
15
|
-
Wrap your Next config
|
|
13
|
+
Wrap your Next config (injected automatically in AceBuilder sandboxes):
|
|
16
14
|
|
|
17
15
|
```js
|
|
18
16
|
// next.config.mjs
|
|
@@ -24,26 +22,22 @@ const nextConfig = {}
|
|
|
24
22
|
export default componentTagger()(nextConfig)
|
|
25
23
|
```
|
|
26
24
|
|
|
27
|
-
##
|
|
25
|
+
## Bundler support
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
| Mode | Tagging |
|
|
28
|
+
|------|---------|
|
|
29
|
+
| `next dev` (Turbopack, default) | Skipped — use runtime fiber resolution in the helper SDK |
|
|
30
|
+
| `next dev --webpack` | Full build-time tagging |
|
|
31
|
+
| `next build` | Full build-time tagging (webpack) |
|
|
30
32
|
|
|
31
|
-
|
|
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
|
-
```
|
|
33
|
+
Turbopack custom loader rules are disabled because they currently produce broken module paths (`welcome.tsx.tsx`).
|
|
41
34
|
|
|
42
35
|
## AceBuilder sandboxes
|
|
43
36
|
|
|
44
|
-
Platform deploy injects
|
|
37
|
+
Platform deploy injects automatically:
|
|
45
38
|
|
|
46
39
|
- `package.json` devDependency: `"@acebuilder/component-tagger": "latest"`
|
|
47
40
|
- `next.config` wrapper via AST injection
|
|
41
|
+
- SDK `<Script>` in root layout
|
|
48
42
|
|
|
49
|
-
User
|
|
43
|
+
User templates stay unchanged.
|
package/index.d.ts
CHANGED
|
@@ -5,37 +5,14 @@ export interface AceBuilderComponentTaggerOptions {
|
|
|
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
|
-
|
|
15
8
|
export type WithAceBuilderComponentTagger = (config: NextConfig) => NextConfig
|
|
16
9
|
|
|
17
10
|
/**
|
|
18
|
-
* Next.js plugin —
|
|
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
|
-
* ```
|
|
11
|
+
* Next.js plugin — webpack pre-loader for component tagging.
|
|
12
|
+
* Default Turbopack dev skips the loader (avoids `*.tsx.tsx` resolution bugs).
|
|
31
13
|
*/
|
|
32
14
|
declare function withAceBuilderComponentTagger(
|
|
33
15
|
options?: AceBuilderComponentTaggerOptions,
|
|
34
16
|
): WithAceBuilderComponentTagger
|
|
35
17
|
|
|
36
|
-
declare namespace withAceBuilderComponentTagger {
|
|
37
|
-
/** Turbopack loader rules — fast path without wrapping webpack. */
|
|
38
|
-
const turbopackRules: AceBuilderTurbopackRules
|
|
39
|
-
}
|
|
40
|
-
|
|
41
18
|
export default withAceBuilderComponentTagger
|
package/index.js
CHANGED
|
@@ -3,33 +3,17 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Next.js plugin for AceBuilder component tagging.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* Legacy path: wrap next.config with this plugin (webpack + turbopack rules).
|
|
6
|
+
* Uses a webpack pre-loader (works with `next dev --webpack` and production builds).
|
|
7
|
+
* Turbopack custom loaders currently break module resolution (`*.tsx.tsx`) — not enabled.
|
|
10
8
|
*/
|
|
11
9
|
const TAGGER_LOADER = require.resolve('./lib/loader')
|
|
12
10
|
|
|
13
|
-
const turbopackRules = {
|
|
14
|
-
'*.{tsx,jsx}': {
|
|
15
|
-
loaders: [TAGGER_LOADER],
|
|
16
|
-
as: '*.js',
|
|
17
|
-
},
|
|
18
|
-
}
|
|
19
|
-
|
|
20
11
|
const componentTagger = (pluginOptions = {}) => (inputConfig = {}) => {
|
|
21
12
|
const test = pluginOptions.test || /\.((j|t)sx)$/i
|
|
22
13
|
|
|
23
14
|
/** @type {import('next').NextConfig} */
|
|
24
15
|
const nextConfig = {
|
|
25
16
|
...inputConfig,
|
|
26
|
-
turbopack: {
|
|
27
|
-
...(inputConfig.turbopack || {}),
|
|
28
|
-
rules: {
|
|
29
|
-
...(inputConfig.turbopack?.rules || {}),
|
|
30
|
-
...turbopackRules,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
17
|
webpack(config, options) {
|
|
34
18
|
config.module.rules.push({
|
|
35
19
|
test,
|
|
@@ -50,6 +34,5 @@ const componentTagger = (pluginOptions = {}) => (inputConfig = {}) => {
|
|
|
50
34
|
return nextConfig
|
|
51
35
|
}
|
|
52
36
|
|
|
53
|
-
componentTagger.turbopackRules = turbopackRules
|
|
54
37
|
module.exports = componentTagger
|
|
55
38
|
module.exports.default = componentTagger
|
package/lib/loader.js
CHANGED
|
@@ -52,19 +52,24 @@ function componentTagger(code, map) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
const resourcePath = this.resourcePath || ''
|
|
56
|
+
const rootContext = this.rootContext || this.context || process.cwd()
|
|
57
|
+
|
|
55
58
|
// Do not process vendor code
|
|
56
|
-
if (/node_modules/.test(
|
|
59
|
+
if (/node_modules/.test(resourcePath)) return done(null, code, inMap)
|
|
57
60
|
|
|
58
61
|
// Parse with Babel (supports JSX and TypeScript)
|
|
59
62
|
const ast = parse(code, {
|
|
60
63
|
sourceType: 'module',
|
|
61
64
|
plugins: ['jsx', 'typescript'],
|
|
62
|
-
sourceFilename:
|
|
65
|
+
sourceFilename: resourcePath,
|
|
63
66
|
})
|
|
64
67
|
|
|
65
68
|
// MagicString allows non-destructive code edits and sourcemap generation
|
|
66
69
|
const ms = new MagicString(code)
|
|
67
|
-
const fileRelative =
|
|
70
|
+
const fileRelative = resourcePath
|
|
71
|
+
? path.relative(rootContext, resourcePath).replace(/\\/g, '/')
|
|
72
|
+
: 'unknown'
|
|
68
73
|
|
|
69
74
|
|
|
70
75
|
let mutated = false
|
|
@@ -151,9 +156,9 @@ function componentTagger(code, map) {
|
|
|
151
156
|
// Create a plain RawSourceMap object for webpack/Turbopack
|
|
152
157
|
const mapStr = ms.generateMap({
|
|
153
158
|
hires: true,
|
|
154
|
-
source:
|
|
159
|
+
source: resourcePath,
|
|
155
160
|
includeContent: true,
|
|
156
|
-
file:
|
|
161
|
+
file: resourcePath,
|
|
157
162
|
}).toString()
|
|
158
163
|
|
|
159
164
|
const outMap = JSON.parse(mapStr)
|
package/package.json
CHANGED