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 build pipeline to create output mirroring graphql

+187 -167
-21
alias/index.mjs
··· 1 - export { version, versionInfo } from 'graphql/version'; 2 - 3 - export { 4 - parse, 5 - parseValue, 6 - parseType, 7 - print, 8 - visit, 9 - visitInParallel, 10 - getVisitFn, 11 - Kind, 12 - } from 'graphql/language'; 13 - 14 - /** Create, format, and print GraphQL errors. */ 15 - export { 16 - GraphQLError, 17 - syntaxError, 18 - locatedError, 19 - printError, 20 - formatError, 21 - } from 'graphql/error';
+1 -2
package.json
··· 4 4 "main": "index.js", 5 5 "license": "MIT", 6 6 "scripts": { 7 - "build": "rollup -c scripts/rollup/config.mjs" 7 + "build": "rollup -c scripts/rollup/config.js" 8 8 }, 9 9 "devDependencies": { 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", 14 13 "@sucrase/jest-plugin": "^2.1.1", 15 14 "babel-plugin-modular-graphql": "^1.0.1", 16 15 "jest": "^27.0.6",
+1 -1
scripts/babel/transformDevAssert.mjs
··· 1 1 const visited = 'visitedByTransformDevAssert'; 2 2 3 3 const warningDevCheckTemplate = ` 4 - if (process.env.NODE_ENV !== 'production') { 4 + if (false) { 5 5 NODE; 6 6 } 7 7 `.trim();
+185
scripts/rollup/config.js
··· 1 + import * as path from 'path'; 2 + 3 + import resolve from '@rollup/plugin-node-resolve'; 4 + import { babel } from '@rollup/plugin-babel'; 5 + import { terser } from 'rollup-plugin-terser'; 6 + 7 + import babelModularGraphQL from 'babel-plugin-modular-graphql'; 8 + import babelTransformDevAssert from '../babel/transformDevAssert.mjs'; 9 + import babelTransformObjectFreeze from '../babel/transformObjectFreeze.mjs'; 10 + 11 + const cwd = process.cwd(); 12 + const graphqlModule = path.join(cwd, 'node_modules/graphql/'); 13 + const virtualModule = path.join(cwd, 'virtual/'); 14 + const aliasModule = path.join(cwd, 'alias/'); 15 + 16 + const EXTERNAL = 'graphql'; 17 + const externalModules = ['dns', 'fs', 'path', 'url']; 18 + const externalPredicate = new RegExp(`^(${externalModules.join('|')})($|/)`); 19 + 20 + const exports = {}; 21 + const importMap = require('babel-plugin-modular-graphql/import-map.json'); 22 + const excludeMap = new Set(['Lexer']); 23 + 24 + for (const key in importMap) { 25 + const { from, local } = importMap[key]; 26 + if (/\/jsutils\//g.test(from) || excludeMap.has(key)) continue; 27 + 28 + const name = from.replace(/^graphql\//, ''); 29 + exports[name] = (exports[name] || '') + `export { ${key} } from '${EXTERNAL}'\n`; 30 + 31 + const parts = name.split('/'); 32 + for (let i = parts.length - 1; i > 0; i--) { 33 + const name = `${parts.slice(0, i).join('/')}/index`; 34 + const from = `./${parts.slice(i).join('/')}`; 35 + exports[name] = (exports[name] || '') + `export { ${local} } from '${from}'\n`; 36 + } 37 + 38 + const index = `export { ${local} } from './${name}'\n`; 39 + exports.index = (exports.index || '') + index; 40 + } 41 + 42 + const manualChunks = (id, utils) => { 43 + let chunk; 44 + if (id.startsWith(graphqlModule)) { 45 + chunk = id.slice(graphqlModule.length); 46 + } else if (id.startsWith(virtualModule)) { 47 + chunk = id.slice(virtualModule.length); 48 + } else if (id.startsWith(aliasModule)) { 49 + chunk = id.slice(aliasModule.length); 50 + } 51 + 52 + if (chunk) { 53 + return chunk.replace(/\.m?js$/, ''); 54 + } 55 + 56 + const { importers } = utils.getModuleInfo(id); 57 + return importers.length === 1 58 + ? manualChunks(importers[0], utils) 59 + : 'shared'; 60 + }; 61 + 62 + export default { 63 + input: 64 + Object.keys(exports).reduce((input, key) => { 65 + input[key] = path.join('./virtual', key); 66 + return input; 67 + }, {}), 68 + external(id) { 69 + return externalPredicate.test(id); 70 + }, 71 + treeshake: { 72 + unknownGlobalSideEffects: false, 73 + tryCatchDeoptimization: false, 74 + moduleSideEffects: false, 75 + }, 76 + plugins: [ 77 + { 78 + async load(id) { 79 + if (!id.startsWith(virtualModule)) 80 + return null; 81 + 82 + const entry = path.relative(virtualModule, id).replace(/\.m?js$/, ''); 83 + return exports[entry] || null; 84 + }, 85 + 86 + async resolveId(source, importer) { 87 + if (!source.startsWith('.') && !source.startsWith('virtual/')) 88 + return null; 89 + 90 + const target = path.join(importer ? path.dirname(importer) : cwd, source); 91 + 92 + const virtualEntry = path.relative(virtualModule, target); 93 + if (!virtualEntry.startsWith('../')) { 94 + const aliasSource = path.join(aliasModule, virtualEntry); 95 + const alias = await this.resolve(aliasSource, undefined, { skipSelf: true }); 96 + return alias || target; 97 + } 98 + 99 + const graphqlEntry = path.relative(graphqlModule, target); 100 + if (!graphqlEntry.startsWith('../')) { 101 + const aliasSource = path.join(aliasModule, graphqlEntry); 102 + const alias = await this.resolve(aliasSource, undefined, { skipSelf: true }); 103 + return alias || target; 104 + } 105 + 106 + return null; 107 + }, 108 + }, 109 + 110 + resolve({ 111 + extensions: ['.mjs', '.js'], 112 + mainFields: ['module', 'browser', 'main'], 113 + preferBuiltins: false, 114 + browser: true, 115 + }), 116 + 117 + babel({ 118 + babelrc: false, 119 + babelHelpers: 'bundled', 120 + presets: [], 121 + plugins: [ 122 + babelTransformDevAssert, 123 + babelTransformObjectFreeze, 124 + babelModularGraphQL, 125 + 'reghex/babel', 126 + ], 127 + }), 128 + 129 + terser({ 130 + warnings: true, 131 + ecma: 5, 132 + keep_fnames: true, 133 + ie8: false, 134 + compress: { 135 + pure_getters: true, 136 + toplevel: true, 137 + booleans_as_integers: false, 138 + keep_fnames: true, 139 + keep_fargs: true, 140 + if_return: false, 141 + ie8: false, 142 + sequences: false, 143 + loops: false, 144 + conditionals: false, 145 + join_vars: false 146 + }, 147 + mangle: { 148 + module: true, 149 + keep_fnames: true, 150 + }, 151 + output: { 152 + beautify: true, 153 + braces: true, 154 + indent_level: 2 155 + } 156 + }), 157 + ], 158 + 159 + treeshake: 'smallest', 160 + shimMissingExports: false, 161 + preserveEntrySignatures: 'allow-extension', 162 + 163 + output: [ 164 + { 165 + chunkFileNames: '[name].js', 166 + entryFileNames: '[name].js', 167 + dir: './dist', 168 + exports: 'named', 169 + format: 'cjs', 170 + minifyInternalExports: false, 171 + hoistTransitiveImports: false, 172 + manualChunks, 173 + }, 174 + { 175 + chunkFileNames: '[name].mjs', 176 + entryFileNames: '[name].mjs', 177 + dir: './dist', 178 + exports: 'named', 179 + format: 'esm', 180 + minifyInternalExports: false, 181 + hoistTransitiveImports: false, 182 + manualChunks, 183 + }, 184 + ], 185 + };
-123
scripts/rollup/config.mjs
··· 1 - import * as path from 'path'; 2 - 3 - import resolve from '@rollup/plugin-node-resolve'; 4 - import replace from '@rollup/plugin-replace'; 5 - import { babel } from '@rollup/plugin-babel'; 6 - import { terser } from 'rollup-plugin-terser'; 7 - 8 - import babelModularGraphQL from 'babel-plugin-modular-graphql'; 9 - import babelTransformDevAssert from '../babel/transformDevAssert.mjs'; 10 - import babelTransformObjectFreeze from '../babel/transformObjectFreeze.mjs'; 11 - 12 - const cwd = process.cwd(); 13 - const externalModules = ['dns', 'fs', 'path', 'url']; 14 - const externalPredicate = new RegExp(`^(${externalModules.join('|')})($|/)`); 15 - 16 - const config = { 17 - input: { 18 - graphql: './alias/index.mjs', 19 - }, 20 - onwarn() {}, 21 - external(id) { 22 - return externalPredicate.test(id); 23 - }, 24 - treeshake: { 25 - unknownGlobalSideEffects: false, 26 - tryCatchDeoptimization: false, 27 - moduleSideEffects: false, 28 - }, 29 - }; 30 - 31 - export default { 32 - ...config, 33 - shimMissingExports: true, 34 - plugins: [ 35 - { 36 - async resolveId(source, importer) { 37 - if (source.startsWith('.') && importer) { 38 - source = path.resolve(path.dirname(importer), source); 39 - } 40 - 41 - const base = path.join(cwd, 'node_modules/graphql/'); 42 - const baseSource = path.relative(base, source); 43 - if (baseSource.startsWith('..')) { 44 - return null; 45 - } 46 - 47 - const aliasSource = path.join(cwd, 'alias/', baseSource); 48 - return this.resolve(aliasSource, importer, { skipSelf: true }); 49 - }, 50 - }, 51 - 52 - resolve({ 53 - extensions: ['.mjs', '.js'], 54 - mainFields: ['module', 'browser', 'main'], 55 - preferBuiltins: false, 56 - browser: true, 57 - }), 58 - 59 - babel({ 60 - babelrc: false, 61 - babelHelpers: 'bundled', 62 - presets: [], 63 - plugins: [ 64 - babelTransformDevAssert, 65 - babelTransformObjectFreeze, 66 - babelModularGraphQL, 67 - 'reghex/babel', 68 - ], 69 - }), 70 - ], 71 - 72 - output: [ 73 - { 74 - chunkFileNames: '[hash].mjs', 75 - entryFileNames: '[name].mjs', 76 - dir: './dist', 77 - exports: 'named', 78 - externalLiveBindings: false, 79 - sourcemap: true, 80 - esModule: false, 81 - indent: false, 82 - freeze: false, 83 - strict: false, 84 - format: 'esm', 85 - }, 86 - { 87 - chunkFileNames: '[hash].min.mjs', 88 - entryFileNames: '[name].min.mjs', 89 - dir: './dist', 90 - exports: 'named', 91 - externalLiveBindings: false, 92 - sourcemap: true, 93 - esModule: false, 94 - indent: false, 95 - freeze: false, 96 - strict: false, 97 - format: 'esm', 98 - plugins: [ 99 - replace({ 100 - 'process.env.NODE_ENV': JSON.stringify('production') 101 - }), 102 - 103 - terser({ 104 - warnings: true, 105 - ecma: 5, 106 - ie8: false, 107 - toplevel: true, 108 - compress: { 109 - keep_infinity: true, 110 - pure_getters: true, 111 - passes: 10 112 - }, 113 - mangle: { 114 - module: true, 115 - }, 116 - output: { 117 - comments: false 118 - } 119 - }), 120 - ], 121 - } 122 - ], 123 - };
-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 - 518 510 "@rollup/pluginutils@^3.1.0": 519 511 version "3.1.0" 520 512 resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-3.1.0.tgz#706b4524ee6dc8b103b3c995533e5ad680c02b9b" ··· 1977 1969 dependencies: 1978 1970 yallist "^4.0.0" 1979 1971 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 - 1987 1972 make-dir@^3.0.0: 1988 1973 version "3.1.0" 1989 1974 resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f" ··· 2379 2364 version "0.7.3" 2380 2365 resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383" 2381 2366 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== 2387 2367 2388 2368 sprintf-js@~1.0.2: 2389 2369 version "1.0.3"