@datadog/mobile-react-native 1.1.4 → 1.1.5
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/lib/commonjs/rum/instrumentation/getJsxRuntime.js +11 -8
- package/lib/commonjs/rum/instrumentation/getJsxRuntime.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/rum/instrumentation/getJsxRuntime.js +11 -8
- package/lib/module/rum/instrumentation/getJsxRuntime.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +5 -3
- package/scripts/replace-react-require.js +78 -0
- package/src/rum/instrumentation/getJsxRuntime.ts +11 -11
- package/src/version.ts +1 -1
|
@@ -12,27 +12,30 @@ exports.getJsxRuntime = void 0;
|
|
|
12
12
|
*/
|
|
13
13
|
const getJsxRuntime = () => {
|
|
14
14
|
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
15
|
-
const [major, minor] = require('react/package.json').version.split('.'); // We need to check on the version of React before
|
|
15
|
+
const [major, minor] = require('react/package.json').version.split('.'); // We need to check on the version of React before requiring 'react/jsx-runtime') as
|
|
16
16
|
// it might crash other exports if the export does not exist (even if there is a try/catch).
|
|
17
17
|
// See: https://github.com/facebook/metro/issues/836
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
if (!isJsxExportedInReactVersion(major, minor)) {
|
|
21
21
|
throw new Error('React version does not support new jsx transform');
|
|
22
|
-
} //
|
|
23
|
-
//
|
|
24
|
-
|
|
22
|
+
} // /!\/!\/!\/!\/!\/!\
|
|
23
|
+
// We have to use inline require here because older React versions (below 16.14) don't have jsx-runtime.
|
|
24
|
+
// metro does not support dynamic require, so 'react/jsx-runtime' is replaced by 'react' on postinstall
|
|
25
|
+
// when react is equal or above 16.14 to avoid this require call to fail during the import phase and then
|
|
26
|
+
// disable all further imports.
|
|
27
|
+
// /!\/!\/!\/!\/!\/!\
|
|
28
|
+
//
|
|
29
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
25
30
|
|
|
26
|
-
const jsxRuntimePackage = isJsxExportedInReactVersion(major, minor) ? 'react/jsx-runtime' : 'react'; // We have to use inline require here because older React versions (below 17) don't have jsx-runtime
|
|
27
|
-
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires, import/no-dynamic-require
|
|
28
31
|
|
|
29
|
-
const jsxRuntime = require(
|
|
32
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
30
33
|
|
|
31
34
|
if (!jsxRuntime.jsx) {
|
|
32
35
|
throw new Error('React version does not support new jsx transform');
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
return jsxRuntime
|
|
38
|
+
return jsxRuntime;
|
|
36
39
|
};
|
|
37
40
|
/**
|
|
38
41
|
* JSX Transform is available for React 16.14.0 (last React 16 version) and above
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["getJsxRuntime.ts"],"names":["getJsxRuntime","major","minor","require","version","split","isJsxExportedInReactVersion","Error","
|
|
1
|
+
{"version":3,"sources":["getJsxRuntime.ts"],"names":["getJsxRuntime","major","minor","require","version","split","isJsxExportedInReactVersion","Error","jsxRuntime","jsx","Number"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AAEO,MAAMA,aAAa,GAAG,MAAM;AAC/B;AACA,QAAM,CAACC,KAAD,EAAQC,KAAR,IAAiBC,OAAO,CAAC,oBAAD,CAAP,CAA8BC,OAA9B,CAAsCC,KAAtC,CAA4C,GAA5C,CAAvB,CAF+B,CAG/B;AACA;AACA;;;AACA,MAAI,CAACC,2BAA2B,CAACL,KAAD,EAAQC,KAAR,CAAhC,EAAgD;AAC5C,UAAM,IAAIK,KAAJ,CAAU,kDAAV,CAAN;AACH,GAR8B,CAU/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,QAAMC,UAAU,GAAGL,OAAO,CAAC,mBAAD,CAA1B;;AACA,MAAI,CAACK,UAAU,CAACC,GAAhB,EAAqB;AACjB,UAAM,IAAIF,KAAJ,CAAU,kDAAV,CAAN;AACH;;AACD,SAAOC,UAAP;AACH,CAvBM;AAyBP;AACA;AACA;;;;;AACA,MAAMF,2BAA2B,GAAG,CAACL,KAAD,EAAgBC,KAAhB,KAA2C;AAC3E,MAAIQ,MAAM,CAACT,KAAD,CAAN,GAAgB,EAApB,EAAwB;AACpB,WAAO,IAAP;AACH;;AACD,MAAIS,MAAM,CAACT,KAAD,CAAN,KAAkB,EAAlB,IAAwBS,MAAM,CAACR,KAAD,CAAN,GAAgB,EAA5C,EAAgD;AAC5C,WAAO,IAAP;AACH;;AACD,SAAO,KAAP;AACH,CARD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nexport const getJsxRuntime = () => {\n // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires\n const [major, minor] = require('react/package.json').version.split('.');\n // We need to check on the version of React before requiring 'react/jsx-runtime') as\n // it might crash other exports if the export does not exist (even if there is a try/catch).\n // See: https://github.com/facebook/metro/issues/836\n if (!isJsxExportedInReactVersion(major, minor)) {\n throw new Error('React version does not support new jsx transform');\n }\n\n // /!\\/!\\/!\\/!\\/!\\/!\\\n // We have to use inline require here because older React versions (below 16.14) don't have jsx-runtime.\n // metro does not support dynamic require, so 'react/jsx-runtime' is replaced by 'react' on postinstall\n // when react is equal or above 16.14 to avoid this require call to fail during the import phase and then\n // disable all further imports.\n // /!\\/!\\/!\\/!\\/!\\/!\\\n //\n // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires\n const jsxRuntime = require('react/jsx-runtime');\n if (!jsxRuntime.jsx) {\n throw new Error('React version does not support new jsx transform');\n }\n return jsxRuntime;\n};\n\n/**\n * JSX Transform is available for React 16.14.0 (last React 16 version) and above\n */\nconst isJsxExportedInReactVersion = (major: string, minor: string): boolean => {\n if (Number(major) > 16) {\n return true;\n }\n if (Number(major) === 16 && Number(minor) > 13) {\n return true;\n }\n return false;\n};\n"]}
|
package/lib/commonjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":";;;;;;AAAA;AACO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.1.
|
|
1
|
+
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":";;;;;;AAAA;AACO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.1.5';\n"]}
|
|
@@ -5,27 +5,30 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export const getJsxRuntime = () => {
|
|
7
7
|
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
8
|
-
const [major, minor] = require('react/package.json').version.split('.'); // We need to check on the version of React before
|
|
8
|
+
const [major, minor] = require('react/package.json').version.split('.'); // We need to check on the version of React before requiring 'react/jsx-runtime') as
|
|
9
9
|
// it might crash other exports if the export does not exist (even if there is a try/catch).
|
|
10
10
|
// See: https://github.com/facebook/metro/issues/836
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
if (!isJsxExportedInReactVersion(major, minor)) {
|
|
14
14
|
throw new Error('React version does not support new jsx transform');
|
|
15
|
-
} //
|
|
16
|
-
//
|
|
17
|
-
|
|
15
|
+
} // /!\/!\/!\/!\/!\/!\
|
|
16
|
+
// We have to use inline require here because older React versions (below 16.14) don't have jsx-runtime.
|
|
17
|
+
// metro does not support dynamic require, so 'react/jsx-runtime' is replaced by 'react' on postinstall
|
|
18
|
+
// when react is equal or above 16.14 to avoid this require call to fail during the import phase and then
|
|
19
|
+
// disable all further imports.
|
|
20
|
+
// /!\/!\/!\/!\/!\/!\
|
|
21
|
+
//
|
|
22
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
18
23
|
|
|
19
|
-
const jsxRuntimePackage = isJsxExportedInReactVersion(major, minor) ? 'react/jsx-runtime' : 'react'; // We have to use inline require here because older React versions (below 17) don't have jsx-runtime
|
|
20
|
-
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires, import/no-dynamic-require
|
|
21
24
|
|
|
22
|
-
const jsxRuntime = require(
|
|
25
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
23
26
|
|
|
24
27
|
if (!jsxRuntime.jsx) {
|
|
25
28
|
throw new Error('React version does not support new jsx transform');
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
return jsxRuntime
|
|
31
|
+
return jsxRuntime;
|
|
29
32
|
};
|
|
30
33
|
/**
|
|
31
34
|
* JSX Transform is available for React 16.14.0 (last React 16 version) and above
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["getJsxRuntime.ts"],"names":["getJsxRuntime","major","minor","require","version","split","isJsxExportedInReactVersion","Error","
|
|
1
|
+
{"version":3,"sources":["getJsxRuntime.ts"],"names":["getJsxRuntime","major","minor","require","version","split","isJsxExportedInReactVersion","Error","jsxRuntime","jsx","Number"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AAEA,OAAO,MAAMA,aAAa,GAAG,MAAM;AAC/B;AACA,QAAM,CAACC,KAAD,EAAQC,KAAR,IAAiBC,OAAO,CAAC,oBAAD,CAAP,CAA8BC,OAA9B,CAAsCC,KAAtC,CAA4C,GAA5C,CAAvB,CAF+B,CAG/B;AACA;AACA;;;AACA,MAAI,CAACC,2BAA2B,CAACL,KAAD,EAAQC,KAAR,CAAhC,EAAgD;AAC5C,UAAM,IAAIK,KAAJ,CAAU,kDAAV,CAAN;AACH,GAR8B,CAU/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,QAAMC,UAAU,GAAGL,OAAO,CAAC,mBAAD,CAA1B;;AACA,MAAI,CAACK,UAAU,CAACC,GAAhB,EAAqB;AACjB,UAAM,IAAIF,KAAJ,CAAU,kDAAV,CAAN;AACH;;AACD,SAAOC,UAAP;AACH,CAvBM;AAyBP;AACA;AACA;;AACA,MAAMF,2BAA2B,GAAG,CAACL,KAAD,EAAgBC,KAAhB,KAA2C;AAC3E,MAAIQ,MAAM,CAACT,KAAD,CAAN,GAAgB,EAApB,EAAwB;AACpB,WAAO,IAAP;AACH;;AACD,MAAIS,MAAM,CAACT,KAAD,CAAN,KAAkB,EAAlB,IAAwBS,MAAM,CAACR,KAAD,CAAN,GAAgB,EAA5C,EAAgD;AAC5C,WAAO,IAAP;AACH;;AACD,SAAO,KAAP;AACH,CARD","sourcesContent":["/*\n * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.\n * This product includes software developed at Datadog (https://www.datadoghq.com/).\n * Copyright 2016-Present Datadog, Inc.\n */\n\nexport const getJsxRuntime = () => {\n // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires\n const [major, minor] = require('react/package.json').version.split('.');\n // We need to check on the version of React before requiring 'react/jsx-runtime') as\n // it might crash other exports if the export does not exist (even if there is a try/catch).\n // See: https://github.com/facebook/metro/issues/836\n if (!isJsxExportedInReactVersion(major, minor)) {\n throw new Error('React version does not support new jsx transform');\n }\n\n // /!\\/!\\/!\\/!\\/!\\/!\\\n // We have to use inline require here because older React versions (below 16.14) don't have jsx-runtime.\n // metro does not support dynamic require, so 'react/jsx-runtime' is replaced by 'react' on postinstall\n // when react is equal or above 16.14 to avoid this require call to fail during the import phase and then\n // disable all further imports.\n // /!\\/!\\/!\\/!\\/!\\/!\\\n //\n // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires\n const jsxRuntime = require('react/jsx-runtime');\n if (!jsxRuntime.jsx) {\n throw new Error('React version does not support new jsx transform');\n }\n return jsxRuntime;\n};\n\n/**\n * JSX Transform is available for React 16.14.0 (last React 16 version) and above\n */\nconst isJsxExportedInReactVersion = (major: string, minor: string): boolean => {\n if (Number(major) > 16) {\n return true;\n }\n if (Number(major) === 16 && Number(minor) > 13) {\n return true;\n }\n return false;\n};\n"]}
|
package/lib/module/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.1.
|
|
1
|
+
{"version":3,"sources":["version.ts"],"names":["version"],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,OAAhB","sourcesContent":["// generated by genversion\nexport const version = '1.1.5';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.1.
|
|
1
|
+
export declare const version = "1.1.5";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/mobile-react-native",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "A client-side React Native module to interact with Datadog",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"src",
|
|
21
21
|
"lib",
|
|
22
|
+
"scripts",
|
|
22
23
|
"android/build.gradle",
|
|
23
24
|
"android/gradle.properties",
|
|
24
25
|
"android/src",
|
|
@@ -39,7 +40,8 @@
|
|
|
39
40
|
"scripts": {
|
|
40
41
|
"test": "jest",
|
|
41
42
|
"lint": "eslint .",
|
|
42
|
-
"prepare": "rm -rf lib && yarn bob build"
|
|
43
|
+
"prepare": "rm -rf lib && yarn bob build",
|
|
44
|
+
"postinstall": "scripts/replace-react-require.js"
|
|
43
45
|
},
|
|
44
46
|
"peerDependencies": {
|
|
45
47
|
"react": ">=16.13.1",
|
|
@@ -73,5 +75,5 @@
|
|
|
73
75
|
]
|
|
74
76
|
]
|
|
75
77
|
},
|
|
76
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "22a120295f0430301fc12bed8393c0243d61b55a"
|
|
77
79
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
5
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
6
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* This script replaces the inline require of 'react' in src/rum/instrumentation/getJsxRuntime.ts
|
|
11
|
+
* to 'react/jsx-runtime'.
|
|
12
|
+
*
|
|
13
|
+
* Context:
|
|
14
|
+
* From its version 16.14, React adds the `jsx` function as a new way to create components. This replaces
|
|
15
|
+
* the createElement function (which is still used in current versions in some cases).
|
|
16
|
+
* From React 18, this seems to become the default. This is also used by default in Expo since Expo 45 at least.
|
|
17
|
+
* On React versions below 16.14, trying to import 'react/jsx-runtime' would fail (see https://github.com/facebook/metro/issues/836)
|
|
18
|
+
* and this failure then disables all imports (see first fix: https://github.com/DataDog/dd-sdk-reactnative/pull/310).
|
|
19
|
+
* However, metro does not support inline requires (see https://github.com/DataDog/dd-sdk-reactnative/issues/353), so
|
|
20
|
+
* we replace the import in this postinstall script.
|
|
21
|
+
*
|
|
22
|
+
* We choose to have 'react/jsx-runtime' as default in the code, that way we don't have to deal with this change in the source when we work on it.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// We can only use requires in node
|
|
26
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
27
|
+
const { readFileSync, writeFileSync } = require('fs');
|
|
28
|
+
|
|
29
|
+
process.stdout.write('[datadog] postinstall replace-react-require starts\n');
|
|
30
|
+
|
|
31
|
+
const GET_JSX_RUNTIME_RELATIVE_PATH = 'rum/instrumentation/getJsxRuntime';
|
|
32
|
+
|
|
33
|
+
const isJsxExportedInReactVersion = (major, minor) => {
|
|
34
|
+
if (Number(major) > 16) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (Number(major) === 16 && Number(minor) > 13) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const replaceReactJsxRequire = () => {
|
|
44
|
+
process.stdout.write('[datadog] replacing react/jsx-runtime by react\n');
|
|
45
|
+
const datadogPath = `${__dirname}/..`;
|
|
46
|
+
const locations = [
|
|
47
|
+
{ directory: `${datadogPath}/src`, extension: 'ts' },
|
|
48
|
+
{ directory: `${datadogPath}/lib/commonjs`, extension: 'js' },
|
|
49
|
+
{ directory: `${datadogPath}/lib/commonjs`, extension: 'js.map' },
|
|
50
|
+
{ directory: `${datadogPath}/lib/module`, extension: 'js' },
|
|
51
|
+
{ directory: `${datadogPath}/lib/module`, extension: 'js.map' }
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
locations.forEach(location => {
|
|
55
|
+
const fileLocation = `${location.directory}/${GET_JSX_RUNTIME_RELATIVE_PATH}.${location.extension}`;
|
|
56
|
+
const file = readFileSync(fileLocation).toString();
|
|
57
|
+
writeFileSync(
|
|
58
|
+
fileLocation,
|
|
59
|
+
file.replace("require('react/jsx-runtime')", "require('react')")
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
// Get React version
|
|
66
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
67
|
+
const [major, minor] = require('react/package.json').version.split('.');
|
|
68
|
+
process.stdout.write(`[datadog] found react version ${major}${minor}\n`);
|
|
69
|
+
|
|
70
|
+
if (!isJsxExportedInReactVersion(major, minor)) {
|
|
71
|
+
replaceReactJsxRequire();
|
|
72
|
+
}
|
|
73
|
+
process.stdout.write('[datadog] postinstall replace-react-require end\n');
|
|
74
|
+
} catch (error) {
|
|
75
|
+
process.stderr.write(
|
|
76
|
+
`[datadog] Error running replace-react-require: ${error}\n`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -7,26 +7,26 @@
|
|
|
7
7
|
export const getJsxRuntime = () => {
|
|
8
8
|
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
9
9
|
const [major, minor] = require('react/package.json').version.split('.');
|
|
10
|
-
// We need to check on the version of React before
|
|
10
|
+
// We need to check on the version of React before requiring 'react/jsx-runtime') as
|
|
11
11
|
// it might crash other exports if the export does not exist (even if there is a try/catch).
|
|
12
12
|
// See: https://github.com/facebook/metro/issues/836
|
|
13
13
|
if (!isJsxExportedInReactVersion(major, minor)) {
|
|
14
14
|
throw new Error('React version does not support new jsx transform');
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
25
|
-
const jsxRuntime = require(
|
|
17
|
+
// /!\/!\/!\/!\/!\/!\
|
|
18
|
+
// We have to use inline require here because older React versions (below 16.14) don't have jsx-runtime.
|
|
19
|
+
// metro does not support dynamic require, so 'react/jsx-runtime' is replaced by 'react' on postinstall
|
|
20
|
+
// when react is equal or above 16.14 to avoid this require call to fail during the import phase and then
|
|
21
|
+
// disable all further imports.
|
|
22
|
+
// /!\/!\/!\/!\/!\/!\
|
|
23
|
+
//
|
|
24
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
25
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
26
26
|
if (!jsxRuntime.jsx) {
|
|
27
27
|
throw new Error('React version does not support new jsx transform');
|
|
28
28
|
}
|
|
29
|
-
return jsxRuntime
|
|
29
|
+
return jsxRuntime;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
/**
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '1.1.
|
|
2
|
+
export const version = '1.1.5';
|