Mirror: The small sibling of the graphql package, slimmed down for client-side libraries.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add babel transform to strip devAssert calls

+86
+1
package.json
··· 10 10 "@babel/core": "^7.15.0", 11 11 "@rollup/plugin-babel": "^5.3.0", 12 12 "@rollup/plugin-node-resolve": "^13.0.4", 13 + "@rollup/plugin-replace": "^3.0.0", 13 14 "@sucrase/jest-plugin": "^2.1.1", 14 15 "babel-plugin-modular-graphql": "^1.0.1", 15 16 "jest": "^27.0.6",
+56
scripts/babel/transformDevAssert.mjs
··· 1 + const visited = 'visitedByTransformDevAssert'; 2 + 3 + const warningDevCheckTemplate = ` 4 + if (process.env.NODE_ENV !== 'production') { 5 + NODE; 6 + } 7 + `.trim(); 8 + 9 + const plugin = ({ template, types: t }) => { 10 + const wrapWithDevCheck = template(warningDevCheckTemplate, { 11 + placeholderPattern: /^NODE$/, 12 + }); 13 + 14 + return { 15 + visitor: { 16 + CallExpression(path) { 17 + const { name } = path.node.callee; 18 + if (path.node[visited]) return; 19 + 20 + if (name === 'devAssert') { 21 + path.node[visited] = true; 22 + 23 + // The production-check may be hoisted if the parent 24 + // is already an if-statement only containing the 25 + // warn call 26 + let p = path; 27 + while (t.isExpressionStatement(p.parentPath.node)) { 28 + if ( 29 + t.isBlockStatement(p.parentPath.parentPath.node) && 30 + p.parentPath.parentPath.node.body.length === 1 && 31 + p.parentPath.parentPath.node.body[0] === path.parentPath.node && 32 + t.isIfStatement(p.parentPath.parentPath.parentPath.node) && 33 + p.parentPath.parentPath.parentPath.node.consequent === 34 + p.parentPath.parentPath.node && 35 + !p.parentPath.parentPath.node.alternate 36 + ) { 37 + p = p.parentPath.parentPath.parentPath; 38 + } else if ( 39 + t.isIfStatement(p.parentPath.parentPath.node) && 40 + p.parentPath.parentPath.node.consequent === p.parentPath.node && 41 + !p.parentPath.parentPath.node.alternate 42 + ) { 43 + p = path.parentPath.parentPath; 44 + } else { 45 + break; 46 + } 47 + } 48 + 49 + p.replaceWith(wrapWithDevCheck({ NODE: p.node })); 50 + } 51 + }, 52 + }, 53 + }; 54 + }; 55 + 56 + export default plugin;
+9
scripts/rollup/config.mjs
··· 1 1 import * as path from 'path'; 2 2 3 3 import resolve from '@rollup/plugin-node-resolve'; 4 + import replace from '@rollup/plugin-replace'; 4 5 import { babel } from '@rollup/plugin-babel'; 5 6 import { terser } from 'rollup-plugin-terser'; 7 + 8 + import babelTransformDevAssert from '../babel/transformDevAssert.mjs'; 6 9 7 10 const cwd = process.cwd(); 8 11 const externalModules = ['dns', 'fs', 'path', 'url']; ··· 12 15 input: { 13 16 graphql: './alias/index.mjs', 14 17 }, 18 + onwarn() {}, 15 19 external(id) { 16 20 return externalPredicate.test(id); 17 21 }, ··· 55 59 babelHelpers: 'bundled', 56 60 presets: [], 57 61 plugins: [ 62 + babelTransformDevAssert, 58 63 'babel-plugin-modular-graphql', 59 64 'reghex/babel', 60 65 ], ··· 88 93 strict: false, 89 94 format: 'esm', 90 95 plugins: [ 96 + replace({ 97 + 'process.env.NODE_ENV': JSON.stringify('production') 98 + }), 99 + 91 100 terser({ 92 101 warnings: true, 93 102 ecma: 5,
+20
yarn.lock
··· 507 507 is-module "^1.0.0" 508 508 resolve "^1.19.0" 509 509 510 + "@rollup/plugin-replace@^3.0.0": 511 + version "3.0.0" 512 + resolved "https://registry.yarnpkg.com/@rollup/plugin-replace/-/plugin-replace-3.0.0.tgz#3a4c9665d4e7a4ce2c360cf021232784892f3fac" 513 + integrity sha512-3c7JCbMuYXM4PbPWT4+m/4Y6U60SgsnDT/cCyAyUKwFHg7pTSfsSQzIpETha3a3ig6OdOKzZz87D9ZXIK3qsDg== 514 + dependencies: 515 + "@rollup/pluginutils" "^3.1.0" 516 + magic-string "^0.25.7" 517 + 510 518 "@rollup/pluginutils@^3.1.0": 511 519 version "3.1.0" 512 520 resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b" ··· 1969 1977 dependencies: 1970 1978 yallist "^4.0.0" 1971 1979 1980 + magic-string@^0.25.7: 1981 + version "0.25.7" 1982 + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.7.tgz#3f497d6fd34c669c6798dcb821f2ef31f5445051" 1983 + integrity sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA== 1984 + dependencies: 1985 + sourcemap-codec "^1.4.4" 1986 + 1972 1987 make-dir@^3.0.0: 1973 1988 version "3.1.0" 1974 1989 resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f" ··· 2364 2379 version "0.7.3" 2365 2380 resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383" 2366 2381 integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ== 2382 + 2383 + sourcemap-codec@^1.4.4: 2384 + version "1.4.8" 2385 + resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4" 2386 + integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA== 2367 2387 2368 2388 sprintf-js@~1.0.2: 2369 2389 version "1.0.3"