diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 159d1de..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,59 +0,0 @@ -# Javascript Node CircleCI 2.0 configuration file -# -# Check https://circleci.com/docs/2.0/language-javascript/ for more details -# -version: 2.1 - -workflows: - all-tests: - jobs: - - test-and-build: - # Override graphql-version to test against specific versions. Type checking is disabled due missing - # definitions for field extensions in older @types/graphql versions - matrix: - parameters: - graphql-version: ['~14.6', '~14.7', '~15.0', '~16.0'] - - test-and-build: - # Leave graphql-version unspecified to respect the lockfile and also run tsc - name: test-and-build-with-typecheck - -jobs: - test-and-build: - parameters: - graphql-version: - type: string - default: '' - - docker: - # specify the version you desire here - - image: circleci/node:latest - - working_directory: ~/repo - - steps: - - checkout - - # Download and cache dependencies - - restore_cache: - keys: - - v1-dependencies-{{ checksum "package.json" }}-<< parameters.graphql-version >> - # fallback to using the latest cache if no exact match is found - - v1-dependencies- - - - when: - condition: << parameters.graphql-version >> - steps: - - run: yarn install --ignore-scripts - - run: yarn --ignore-scripts add --dev graphql@<< parameters.graphql-version >> - - unless: - condition: << parameters.graphql-version >> - steps: - - run: yarn install --frozen-lockfile - - - save_cache: - paths: - - node_modules - key: v1-dependencies-{{ checksum "package.json" }}-<< parameters.graphql-version >> - - # run tests! - - run: yarn test diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..a633b2e --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,84 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test-and-build: + runs-on: ubuntu-latest + strategy: + matrix: + graphql-version: ['~15.0', '~16.0'] + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 'latest' + + - name: Restore cache + uses: actions/cache@v2 + with: + path: node_modules + key: v1-dependencies-${{ hashFiles('package.json') }}-${{ matrix.graphql-version }} + restore-keys: | + v1-dependencies- + + - name: Install dependencies + if: matrix.graphql-version != '' + run: yarn install --ignore-scripts + + - name: Add specific graphql version + if: matrix.graphql-version != '' + run: yarn --ignore-scripts add --dev graphql@${{ matrix.graphql-version }} + + - name: Install dependencies with frozen lockfile + if: matrix.graphql-version == '' + run: yarn install --frozen-lockfile + + - name: Save cache + uses: actions/cache@v2 + with: + path: node_modules + key: v1-dependencies-${{ hashFiles('package.json') }}-${{ matrix.graphql-version }} + + - name: Run tests + run: yarn test + + test-and-build-with-typecheck: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 'latest' + + - name: Restore cache + uses: actions/cache@v2 + with: + path: node_modules + key: v1-dependencies-${{ hashFiles('package.json') }} + restore-keys: | + v1-dependencies- + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Save cache + uses: actions/cache@v2 + with: + path: node_modules + key: v1-dependencies-${{ hashFiles('package.json') }} + + - name: Run tests + run: yarn test diff --git a/README.md b/README.md index e94943a..935ce89 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [](https://www.npmjs.com/package/graphql-query-complexity) [](https://badge.fury.io/js/graphql-query-complexity) -[](https://circleci.com/gh/slicknode/graphql-query-complexity) [](https://twitter.com/slicknode) This library provides GraphQL query analysis to reject complex queries to your GraphQL server. diff --git a/fix-hybrid-module.sh b/fix-hybrid-module.sh index 4792b5f..3c46b4e 100755 --- a/fix-hybrid-module.sh +++ b/fix-hybrid-module.sh @@ -1,11 +1,40 @@ +#!/bin/bash + +# Create package.json for CommonJS cat >dist/cjs/package.json <<!EOF { "type": "commonjs" } !EOF +# Define the file paths +cjs_file_path="dist/cjs/QueryComplexity.js" +esm_file_path="dist/esm/QueryComplexity.js" +find_path="dist/esm" + +# Detect the operating system and use the appropriate sed command +if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS (BSD sed) + sed -i '' 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "$cjs_file_path" +else + # Linux (GNU sed) + sed -i 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "$cjs_file_path" +fi + +# Create package.json for ES modules cat >dist/esm/package.json <<!EOF { "type": "module" } !EOF + +# Detect the operating system and use the appropriate sed command +if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS (BSD sed) + sed -i '' 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "$esm_file_path" + find "$find_path" -type f -name "*.js" -exec sed -i '' 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} + +else + # Linux (GNU sed) + sed -i 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "$esm_file_path" + find "$find_path" -type f -name "*.js" -exec sed -i 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} + +fi \ No newline at end of file diff --git a/fix-hybrid-module.test.cjs.sh b/fix-hybrid-module.test.cjs.sh index 335c29a..bc17a03 100755 --- a/fix-hybrid-module.test.cjs.sh +++ b/fix-hybrid-module.test.cjs.sh @@ -2,4 +2,14 @@ cat >dist/test/cjs/package.json <<!EOF { "type": "commonjs" } -!EOF \ No newline at end of file +!EOF + +file_path="dist/test/cjs/QueryComplexity.js" + +if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS (BSD sed) + sed -i '' 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "$file_path" +else + # Linux (GNU sed) + sed -i 's/require("graphql\/execution\/values")/require("graphql\/execution\/values.js")/' "$file_path" +fi \ No newline at end of file diff --git a/fix-hybrid-module.test.esm.sh b/fix-hybrid-module.test.esm.sh index 2fa0e80..e0c9835 100755 --- a/fix-hybrid-module.test.esm.sh +++ b/fix-hybrid-module.test.esm.sh @@ -3,3 +3,17 @@ cat >dist/test/esm/package.json <<!EOF "type": "module" } !EOF + +file_path="dist/test/esm/QueryComplexity.js" +find_path="dist/test/esm" + +# Detect the operating system and use the appropriate sed command +if [[ "$OSTYPE" == "darwin"* ]]; then + # macOS (BSD sed) + sed -i '' 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "$file_path" + find "$find_path" -type f -name "*.js" -exec sed -i '' 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} + +else + # Linux (GNU sed) + sed -i 's/from '\''graphql\/execution\/values'\'';/from '\''graphql\/execution\/values.mjs'\'';/' "$file_path" + find "$find_path" -type f -name "*.js" -exec sed -i 's/from '\''graphql'\'';/from '\''graphql\/index.mjs'\'';/' {} + +fi diff --git a/package.json b/package.json index 20a1fdf..13a62c7 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "build:test:esm": "tsc -p ./tsconfig.test.esm.json && ./fix-hybrid-module.test.esm.sh", "test": "npm run lint && npm run build:test:cjs && npm run testonly:cjs && npm run build:test:esm && npm run testonly:esm", "testonly:cjs": "mocha --check-leaks --exit --full-trace 'dist/test/cjs/**/__tests__/**/*-test.js'", - "testonly:esm": "mocha -n experimental-json-modules --check-leaks --exit --full-trace 'dist/test/esm/**/__tests__/**/*-test.js'", + "testonly:esm": "mocha -n experimental-json-modules --loader=ts-node/esm --check-leaks --exit --full-trace 'dist/test/esm/**/__tests__/**/*-test.js'", "dist": "npm run clean && npm run build", "prepare": "npm run clean && npm run dist" }, @@ -27,7 +27,7 @@ "lodash.get": "^4.4.2" }, "peerDependencies": { - "graphql": "^14.6.0 || ^15.0.0 || ^16.0.0" + "graphql": "^15.0.0 || ^16.0.0" }, "files": [ "dist", @@ -47,7 +47,9 @@ ".": { "import": "./dist/esm/index.js", "require": "./dist/cjs/index.js" - } + }, + "./esm": "./dist/esm/index.js", + "./cjs": "./dist/cjs/index.js" }, "author": "Ivo Meißner", "license": "MIT",