Skip to content

Commit

Permalink
feat: Hybrid module
Browse files Browse the repository at this point in the history
Signed-off-by: Diwank Singh Tomer <[email protected]>
  • Loading branch information
creatorrr committed Mar 26, 2021
1 parent d1e4d83 commit 02b359f
Show file tree
Hide file tree
Showing 11 changed files with 20,241 additions and 20,225 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Generated files
/docs/
/lib/
/src/generated/
/esm/
/cjs/**/*
!/cjs/codegen.js
!/cjs/package.json

# Vim shit
*.swp
Expand Down
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Include lib
!/lib/
!/esm/
!/cjs/

# Generated files
/docs/
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
40,398 changes: 20,188 additions & 20,210 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
{
"name": "@mauna/sdk",
"version": "0.2.2",
"version": "0.2.3",
"description": "Code generated from Mauna API schema for CLI, SDK etc",
"main": "lib/index.js",
"main": "./cjs/index.js",
"module": "./esm/index.js",
"type": "module",
"exports": {
"./esm": "./esm/index.js"
},
"files": [
"cjs/",
"esm/"
],
"scripts": {
"test": "jest",
"test": "./tests/checkImport.js && jest --passWithNoTests",
"version-bump": "git diff-index --quiet HEAD -- || json-bump package.json",
"codegen": "validEnv HASURA_ADMIN_SECRET && graphql-codegen --config codegen.js",
"tsc": "tsc",
"codegen": "validEnv HASURA_ADMIN_SECRET && graphql-codegen --config cjs/codegen.js",
"tsc": "tsc && tsc -p tsconfig-cjs.json",
"docs": "typedoc src/index.ts --out ./docs",
"prepublishOnly": "npm run build && npm test",
"build": "npm run codegen && npm run tsc && npm run docs"
},
"repository": {
Expand All @@ -28,6 +38,7 @@
"@graphql-codegen/typescript-graphql-request": "^3.0.2",
"@graphql-codegen/typescript-oclif": "^1.17.9",
"@graphql-codegen/typescript-operations": "^1.17.14",
"@types/isomorphic-fetch": "^0.0.35",
"@types/lodash": "^4.14.168",
"json-bump": "^1.0.2",
"prettier": "2.2.1",
Expand Down
3 changes: 2 additions & 1 deletion src/utils/auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require("isomorphic-fetch");
import isomorphicFetch from "isomorphic-fetch";
isomorphicFetch;

import { authEndpoint } from "../config";
import {
Expand Down
5 changes: 4 additions & 1 deletion src/utils/gqlLodash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import flow from "lodash/flow";
import zip from "lodash/zip";

import { default as _gql } from "graphql-tag";
import { graphqlLodash } from "graphql-lodash";

// Need to do this dance to support both esm and cjs packages
import graphqlLodashPkg from "graphql-lodash";
const { graphqlLodash } = graphqlLodashPkg ? graphqlLodashPkg : require("graphql-lodash");

const merge = flow([zip, flatten, compact]);

Expand Down
6 changes: 6 additions & 0 deletions tests/checkImport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
":" //# comment; exec /usr/bin/env node --es-module-specifier-resolution=node "$0" "$@"

import Mauna from "../esm/index.js";

console.log("mauna", Mauna);
9 changes: 9 additions & 0 deletions tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "CommonJS",
"outDir": "./cjs",
"target": "es2015"
}
}

13 changes: 7 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"target": "ES2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "ES2020" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"resolveJsonModule": true,
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
Expand All @@ -15,7 +15,7 @@
"declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
"sourceMap": true /* Generates corresponding '.map' file. */,
// "outFile": "./index.js", /* Concatenate and emit output to single file. */
"outDir": "./lib" /* Redirect output structure to the directory. */,
"outDir": "./esm" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
Expand All @@ -39,17 +39,18 @@
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
"pretty": true,
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
Expand Down

0 comments on commit 02b359f

Please sign in to comment.