@dcoder-x/next 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.
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const plugin_shared_1 = require("@dcoder-x/plugin-shared");
|
|
4
|
+
const loader = function (source) {
|
|
5
|
+
const input = typeof source === 'string' ? source : source.toString('utf-8');
|
|
6
|
+
const filePath = this.resourcePath;
|
|
7
|
+
const result = (0, plugin_shared_1.injectClippyIds)(input, filePath);
|
|
8
|
+
try {
|
|
9
|
+
// Attach metadata to the webpack module so the plugin can collect it later
|
|
10
|
+
;
|
|
11
|
+
this._module = this._module || {};
|
|
12
|
+
this._module.__clippy_injected = result.injected || [];
|
|
13
|
+
// Some webpack versions expose buildInfo on the module
|
|
14
|
+
try {
|
|
15
|
+
;
|
|
16
|
+
this.buildInfo = this.buildInfo || {};
|
|
17
|
+
this.buildInfo.__clippy_injected = result.injected || [];
|
|
18
|
+
}
|
|
19
|
+
catch { }
|
|
20
|
+
}
|
|
21
|
+
catch { }
|
|
22
|
+
this.callback(null, result.source);
|
|
23
|
+
};
|
|
24
|
+
exports.default = loader;
|
|
25
|
+
module.exports = loader;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClippyPluginOptions } from '@
|
|
1
|
+
import type { ClippyPluginOptions } from '@dcoder-x/plugin-shared';
|
|
2
2
|
export declare function withClippy(nextConfig: Record<string, any> | undefined, options: ClippyPluginOptions): {
|
|
3
3
|
webpack(config: any, context: any): any;
|
|
4
4
|
};
|
package/dist/ClippyNextPlugin.js
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.withClippy = withClippy;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
4
8
|
const ClippyWebpackPlugin_1 = require("./ClippyWebpackPlugin");
|
|
5
9
|
function withClippy(nextConfig = {}, options) {
|
|
6
10
|
return {
|
|
7
11
|
...nextConfig,
|
|
8
12
|
webpack(config, context) {
|
|
9
13
|
if (!context.isServer) {
|
|
14
|
+
const loaderPath = path_1.default.join(__dirname, 'ClippyInjectLoader.js');
|
|
15
|
+
config.module.rules = config.module.rules || [];
|
|
16
|
+
config.module.rules.unshift({
|
|
17
|
+
test: /\.[jt]sx?$/,
|
|
18
|
+
exclude: /node_modules/,
|
|
19
|
+
use: [{ loader: loaderPath }],
|
|
20
|
+
});
|
|
10
21
|
config.plugins.push(new ClippyWebpackPlugin_1.ClippyWebpackPlugin(options, context));
|
|
11
22
|
}
|
|
12
23
|
if (typeof nextConfig.webpack === 'function') {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClippyWebpackPlugin = void 0;
|
|
4
|
-
const RouteExtractor_1 = require("@
|
|
5
|
-
const ComponentExtractor_1 = require("@
|
|
6
|
-
const SelectorGenerator_1 = require("@
|
|
7
|
-
const FlowInferrer_1 = require("@
|
|
8
|
-
const PackageBuilder_1 = require("@
|
|
9
|
-
const PackageWriter_1 = require("@
|
|
10
|
-
const Uploader_1 = require("@
|
|
4
|
+
const RouteExtractor_1 = require("@dcoder-x/plugin-shared/extractors/RouteExtractor");
|
|
5
|
+
const ComponentExtractor_1 = require("@dcoder-x/plugin-shared/extractors/ComponentExtractor");
|
|
6
|
+
const SelectorGenerator_1 = require("@dcoder-x/plugin-shared/extractors/SelectorGenerator");
|
|
7
|
+
const FlowInferrer_1 = require("@dcoder-x/plugin-shared/extractors/FlowInferrer");
|
|
8
|
+
const PackageBuilder_1 = require("@dcoder-x/plugin-shared/upload/PackageBuilder");
|
|
9
|
+
const PackageWriter_1 = require("@dcoder-x/plugin-shared/upload/PackageWriter");
|
|
10
|
+
const Uploader_1 = require("@dcoder-x/plugin-shared/upload/Uploader");
|
|
11
|
+
const plugin_shared_1 = require("@dcoder-x/plugin-shared");
|
|
11
12
|
class ClippyWebpackPlugin {
|
|
12
13
|
constructor(options, context) {
|
|
13
14
|
this.options = options;
|
|
@@ -19,36 +20,86 @@ class ClippyWebpackPlugin {
|
|
|
19
20
|
return;
|
|
20
21
|
try {
|
|
21
22
|
const routes = await new RouteExtractor_1.RouteExtractor(this.context.dir).extract();
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
23
|
+
const extractor = new ComponentExtractor_1.ComponentExtractor({ type: 'webpack', compilation }, routes);
|
|
24
|
+
const elements = await extractor.extract();
|
|
25
|
+
const components = await extractor.extractComponents();
|
|
26
|
+
// Collect injected metadata attached by the loader (if any)
|
|
27
|
+
const injectedMap = {};
|
|
28
|
+
try {
|
|
29
|
+
const modules = compilation.modules || [];
|
|
30
|
+
for (const mod of modules) {
|
|
31
|
+
try {
|
|
32
|
+
const resource = mod.resource || mod.userRequest || (mod.identifier && mod.identifier());
|
|
33
|
+
if (!resource)
|
|
34
|
+
continue;
|
|
35
|
+
const meta = mod.__clippy_injected || mod.buildInfo?.__clippy_injected || (mod._module && mod._module.__clippy_injected);
|
|
36
|
+
if (meta && Array.isArray(meta) && meta.length) {
|
|
37
|
+
injectedMap[resource] = meta;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch { }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch { }
|
|
44
|
+
const selectors = new SelectorGenerator_1.SelectorGenerator().generate(elements, injectedMap);
|
|
45
|
+
const flows = new FlowInferrer_1.FlowInferrer(routes, elements, components).infer();
|
|
25
46
|
const packageBuilder = new PackageBuilder_1.PackageBuilder();
|
|
26
|
-
const
|
|
47
|
+
const artifacts = packageBuilder.buildArtifacts({
|
|
27
48
|
buildId: this.context.buildId,
|
|
28
49
|
bundler: 'webpack',
|
|
29
50
|
routes,
|
|
30
|
-
components,
|
|
31
51
|
selectors,
|
|
32
52
|
flows,
|
|
53
|
+
components,
|
|
33
54
|
});
|
|
34
55
|
if (this.options.localOutputDir) {
|
|
35
|
-
const written = new PackageWriter_1.PackageWriter().
|
|
36
|
-
console.log(`[Clippy]
|
|
56
|
+
const written = new PackageWriter_1.PackageWriter().writeArtifacts(this.options.localOutputDir, artifacts);
|
|
57
|
+
console.log(`[Clippy] Policy artifacts written: ${written.policyPath}, ${written.selectorsPath}`);
|
|
58
|
+
try {
|
|
59
|
+
const fs = require('fs');
|
|
60
|
+
const path = require('path');
|
|
61
|
+
fs.writeFileSync(path.join(this.options.localOutputDir, 'clippy-injected.json'), JSON.stringify(injectedMap, null, 2), 'utf-8');
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
/* ignore write errors */
|
|
65
|
+
}
|
|
37
66
|
}
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
routes: knowledgePackage.routes,
|
|
42
|
-
components: knowledgePackage.components,
|
|
43
|
-
selectors: knowledgePackage.selectors,
|
|
44
|
-
flows: knowledgePackage.flows,
|
|
45
|
-
});
|
|
46
|
-
const uploaded = await new Uploader_1.Uploader(this.options).upload(pkg);
|
|
47
|
-
if (uploaded) {
|
|
48
|
-
console.log('[Clippy] Knowledge package uploaded.');
|
|
67
|
+
const artifactUpload = await (0, plugin_shared_1.performUpload)(artifacts, this.options);
|
|
68
|
+
if (artifactUpload.skipped) {
|
|
69
|
+
console.log('[Clippy] Policy artifact upload skipped.');
|
|
49
70
|
}
|
|
50
71
|
else {
|
|
51
|
-
console.log(
|
|
72
|
+
console.log(`[Clippy] Policy artifacts uploaded (${artifactUpload.mode}).`);
|
|
73
|
+
}
|
|
74
|
+
const uploader = new Uploader_1.Uploader(this.options);
|
|
75
|
+
if (this.options.legacyPackageMode) {
|
|
76
|
+
const knowledgePackage = packageBuilder.buildPackage({
|
|
77
|
+
buildId: this.context.buildId,
|
|
78
|
+
bundler: 'webpack',
|
|
79
|
+
routes,
|
|
80
|
+
components: elements,
|
|
81
|
+
selectors,
|
|
82
|
+
flows,
|
|
83
|
+
});
|
|
84
|
+
if (this.options.localOutputDir) {
|
|
85
|
+
const written = new PackageWriter_1.PackageWriter().write(this.options.localOutputDir, knowledgePackage);
|
|
86
|
+
console.log(`[Clippy] Legacy knowledge package written: ${written.jsonPath}`);
|
|
87
|
+
}
|
|
88
|
+
const legacyPayload = packageBuilder.build({
|
|
89
|
+
buildId: knowledgePackage.buildId,
|
|
90
|
+
bundler: knowledgePackage.bundler,
|
|
91
|
+
routes: knowledgePackage.routes,
|
|
92
|
+
components: knowledgePackage.components,
|
|
93
|
+
selectors: knowledgePackage.selectors,
|
|
94
|
+
flows: knowledgePackage.flows,
|
|
95
|
+
});
|
|
96
|
+
const legacyUploaded = await uploader.upload(legacyPayload);
|
|
97
|
+
if (legacyUploaded) {
|
|
98
|
+
console.log('[Clippy] Legacy knowledge package uploaded.');
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
console.log('[Clippy] Legacy knowledge package upload skipped.');
|
|
102
|
+
}
|
|
52
103
|
}
|
|
53
104
|
}
|
|
54
105
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcoder-x/next",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dcoder-x/plugin-shared": "
|
|
13
|
+
"@dcoder-x/plugin-shared": "workspace:*"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"next": ">=13.0.0",
|