Skip to content

Commit

Permalink
Update dependencies for generator package (#23)
Browse files Browse the repository at this point in the history
* fix the tests

* update dependencies

* adapt code and tests to use ESM

* update CHANGELOG

* update node version in package json

* remove unnecessary comments

* update GitHub actions - merge back with coverage package

* tsconfig - unify case
  • Loading branch information
Prusdrum committed Jul 26, 2023
1 parent d110dae commit 2e4bb5b
Show file tree
Hide file tree
Showing 15 changed files with 1,707 additions and 3,239 deletions.
4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,3 @@ updates:
interval: "daily"
reviewers:
- IchordeDionysos
ignore:
- dependency-name: "meow"
# Ignore meow 10.x for now as jest does not work properly with ES modules yet.
versions: [ "10.x" ]
81 changes: 0 additions & 81 deletions .github/workflows/checks-coverage.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ on:
pull_request:
branches:
- main
paths:
- 'firebase-rules-generator/**'
push:
branches:
- main
paths:
- 'firebase-rules-generator/**'

jobs:
lint:
Expand All @@ -18,10 +14,9 @@ jobs:
strategy:
matrix:
package:
- 'firebase-rules-coverage'
- 'firebase-rules-generator'
node_version:
- '12'
- '14'
- '16'
- '18'
fail-fast: false
Expand All @@ -43,10 +38,9 @@ jobs:
strategy:
matrix:
package:
- 'firebase-rules-coverage'
- 'firebase-rules-generator'
node_version:
- '12'
- '14'
- '16'
- '18'
fail-fast: false
Expand Down
7 changes: 6 additions & 1 deletion firebase-rules-generator/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"extends": "./node_modules/gts/"
"extends": "./node_modules/gts/",
"rules": {
"node/no-unpublished-import": ["error", {
"allowModules": ["ts-jest", "@jest/globals"]
}]
}
}
1 change: 1 addition & 0 deletions firebase-rules-generator/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.14.2
File renamed without changes.
5 changes: 5 additions & 0 deletions firebase-rules-generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# @simpleclub/firebase-rules-generator

## 1.0.0

- Updates dependencies. It switches to ESM (type: "module") ([due to meow upgrade](https://github.com/sindresorhus/meow/releases/tag/v10.0.0))
- **Breaking**: It requires Node.js version 16 or higher ([also due to meow upgrade](https://github.com/sindresorhus/meow/releases/tag/v12.0.0))

## 0.1.1

- Fixes command `firebase-build-rules` not being added to the project after installation.
Expand Down
15 changes: 13 additions & 2 deletions firebase-rules-generator/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
module.exports = {
import type {JestConfigWithTsJest} from 'ts-jest';

// This configuration enables ESM
// and is inspired by
// https://kulshekhar.github.io/ts-jest/docs/guides/esm-support/
const config: JestConfigWithTsJest = {
roots: ['<rootDir>/src/', '<rootDir>/test/'],
preset: 'ts-jest',
testEnvironment: 'node',
testRegex: '(/__tests__/.*|(\\.|/)(test))\\.[jt]sx?$',
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(mt|t|cj|j)s$': ['ts-jest', {useESM: true}],
},
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts'],
coverageReporters: ['text', 'text-summary', ['lcov', {projectRoot: '../'}]],
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
};

export default config;
20 changes: 11 additions & 9 deletions firebase-rules-generator/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@simpleclub/firebase-rules-generator",
"version": "0.1.1",
"version": "1.0.0",
"type": "module",
"description": "Helper package for building more complex Firebase rules with support for imports.",
"main": "build/src/index.js",
"repository": "https://github.com/simpleclub/firebase-rules-helper",
Expand All @@ -11,7 +12,7 @@
"firebase-rules-generator": "src/cli.js"
},
"engines": {
"node": ">=12"
"node": ">=16"
},
"scripts": {
"lint": "gts lint",
Expand All @@ -21,21 +22,22 @@
"prepare": "npm run compile",
"pretest": "npm run compile",
"posttest": "npm run lint",
"test": "jest --runInBand",
"test:dev": "jest --runInBand --watch",
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest --runInBand",
"test:dev": "NODE_OPTIONS=\"--experimental-vm-modules\" jest --runInBand --watch",
"release": "yarn clean && yarn compile && cp package.json ./build && cp README.md ./build && cp CHANGELOG.md ./build && yarn publish ./build"
},
"dependencies": {
"meow": "^9.0.0",
"meow": "^12.0.1",
"source-map": "^0.7.3"
},
"devDependencies": {
"@types/jest": "^26.0.23",
"@jest/globals": "^29.6.1",
"@types/jest": "^29.5.3",
"@types/node": "^15.6.1",
"gts": "^3.1.0",
"jest": "^26.6.3",
"ts-jest": "^26.5.6",
"jest": "^29.6.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.0.0",
"typescript": "^4.3.2"
"typescript": "^5.1.6"
}
}
9 changes: 5 additions & 4 deletions firebase-rules-generator/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node

import * as meow from 'meow';
import meow from 'meow';
import * as path from 'path';
import {buildFile} from './build';
import {buildFile} from './build.js';

const cli = meow(
`
Expand All @@ -18,15 +18,16 @@ const cli = meow(
$ firebase-build-rules rules/index.rules --no-source-map --output storage.rules
`,
{
importMeta: import.meta,
flags: {
output: {
type: 'string',
alias: 'o',
shortFlag: 'o',
isRequired: true,
},
sourceMap: {
type: 'boolean',
alias: 's',
shortFlag: 's',
default: true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion firebase-rules-generator/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {resolveImports, buildFile} from './build';
export {resolveImports, buildFile} from './build.js';
31 changes: 16 additions & 15 deletions firebase-rules-generator/test/build.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {jest} from '@jest/globals';
import * as fs from 'fs';
import {buildFile, resolveImports} from '../src';
import {buildFile, resolveImports} from '../src/index.js';
import {SourceMapGenerator} from 'source-map';

global.console = {
Expand All @@ -9,24 +10,22 @@ global.console = {

describe('build file', () => {
afterEach(() => {
fs.rmdirSync('fixtures/output', {
recursive: true,
});
if (fs.existsSync('fixtures/output')) {
fs.rmSync('fixtures/output', {
recursive: true,
});
}
});

it('should generate a rules file', async () => {
await buildFile(
'fixtures/index.rules',
'fixtures/output/firestore.rules',
false
);
it('should generate a rules file', () => {
buildFile('fixtures/index.rules', 'fixtures/output/firestore.rules', false);
expect(
fs.readFileSync('fixtures/output/firestore.rules').toString()
).toEqual(fs.readFileSync('fixtures/firestore.rules').toString());
});

it('should generate a source map file', async () => {
await buildFile('fixtures/index.rules', 'fixtures/output/firestore.rules');
it('should generate a source map file', () => {
buildFile('fixtures/index.rules', 'fixtures/output/firestore.rules');
expect(
fs.readFileSync('fixtures/output/firestore.rules.map').toString()
).toEqual(fs.readFileSync('fixtures/firestore.rules.map').toString());
Expand All @@ -35,9 +34,11 @@ describe('build file', () => {

describe('resolve imports', () => {
afterEach(() => {
fs.rmdirSync('fixtures/output', {
recursive: true,
});
if (fs.existsSync('fixtures/output')) {
fs.rmSync('fixtures/output', {
recursive: true,
});
}
});

it('should resolve imports', () => {
Expand Down
Loading

0 comments on commit 2e4bb5b

Please sign in to comment.