gtx-cli 1.1.11 → 1.1.13
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.
|
@@ -13,7 +13,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.default = createDictionaryUpdates;
|
|
16
|
-
const react_1 = __importDefault(require("react"));
|
|
17
16
|
const fs_1 = __importDefault(require("fs"));
|
|
18
17
|
const path_1 = __importDefault(require("path"));
|
|
19
18
|
const os_1 = __importDefault(require("os"));
|
|
@@ -36,7 +35,6 @@ function createDictionaryUpdates(options, dictionaryPath, esbuildConfig) {
|
|
|
36
35
|
const bundledCode = result.outputFiles[0].text;
|
|
37
36
|
const tempFilePath = path_1.default.join(os_1.default.tmpdir(), 'bundled-dictionary.js');
|
|
38
37
|
fs_1.default.writeFileSync(tempFilePath, bundledCode);
|
|
39
|
-
globalThis.React = react_1.default;
|
|
40
38
|
// Load the module using require
|
|
41
39
|
let dictionaryModule;
|
|
42
40
|
try {
|
|
@@ -117,11 +117,19 @@ function scanForContent(options, pkg, framework) {
|
|
|
117
117
|
if (framework === 'next-pages' &&
|
|
118
118
|
options.addGTProvider &&
|
|
119
119
|
(baseFileName === '_app.tsx' || baseFileName === '_app.jsx')) {
|
|
120
|
-
// Check if this is the
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
// Check if this is the Component element with pageProps
|
|
121
|
+
const isComponentWithPageProps = t.isJSXElement(path.node) &&
|
|
122
|
+
t.isJSXIdentifier(path.node.openingElement.name) &&
|
|
123
|
+
path.node.openingElement.name.name === 'Component' &&
|
|
124
|
+
path.node.openingElement.attributes.some((attr) => t.isJSXSpreadAttribute(attr) &&
|
|
125
|
+
t.isIdentifier(attr.argument) &&
|
|
126
|
+
attr.argument.name === 'pageProps');
|
|
127
|
+
if (!isComponentWithPageProps) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
123
130
|
// Check if GTProvider already exists in the ancestors
|
|
124
131
|
let hasGTProvider = false;
|
|
132
|
+
let currentPath = path;
|
|
125
133
|
while (currentPath.parentPath) {
|
|
126
134
|
if (t.isJSXElement(currentPath.node) &&
|
|
127
135
|
t.isJSXIdentifier(currentPath.node.openingElement.name) &&
|
|
@@ -129,13 +137,10 @@ function scanForContent(options, pkg, framework) {
|
|
|
129
137
|
hasGTProvider = true;
|
|
130
138
|
break;
|
|
131
139
|
}
|
|
132
|
-
if (t.isExportDefaultDeclaration(currentPath.parentPath.node)) {
|
|
133
|
-
isDefaultExport = true;
|
|
134
|
-
}
|
|
135
140
|
currentPath = currentPath.parentPath;
|
|
136
141
|
}
|
|
137
|
-
if (
|
|
138
|
-
// Wrap the
|
|
142
|
+
if (!hasGTProvider) {
|
|
143
|
+
// Wrap the Component element with GTProvider
|
|
139
144
|
const gtProviderJsx = t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier('GTProvider'), [t.jsxSpreadAttribute(t.identifier('gtConfig'))], false), t.jsxClosingElement(t.jsxIdentifier('GTProvider')), [path.node]);
|
|
140
145
|
path.replaceWith(gtProviderJsx);
|
|
141
146
|
usedImports.push('GTProvider');
|