Skip to content

Commit

Permalink
fix(deps): update dependency flat to v6 (#579)
Browse files Browse the repository at this point in the history
* fix(deps): update dependency flat to v6

* Change import of flatten

* Use import for flatten

Resolves error:

`Error [ERR_REQUIRE_ESM]: require() of ES Module /home/runner/work/google-cloudevents/google-cloudevents/tools/proto2jsonschema/node_modules/flat/index.js from /home/runner/work/google-cloudevents/google-cloudevents/tools/proto2jsonschema/postgen.js not supported.
Instead change the require of index.js in /home/runner/work/google-cloudevents/google-cloudevents/tools/proto2jsonschema/postgen.js to a dynamic import() which is available in all CommonJS modules.`

* Undo changes to postgen.js

* Use import in postgen.js

* set type to module package.json

* resolve __dirname error

ReferenceError: __dirname is not defined in ES module scope

---------

Co-authored-by: Roger Martinez <31829545+rogerthatdev@users.noreply.github.com>
  • Loading branch information
renovate-bot and rogerthatdev authored Nov 29, 2023
1 parent 5e9a4f0 commit 2f0c0ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
11 changes: 7 additions & 4 deletions tools/proto2jsonschema/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions tools/proto2jsonschema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"postgen": "node postgen.js"
},
"dependencies": {
"flat": "^5.0.2",
"flat": "^6.0.0",
"protobufjs": "^7.0.0",
"recursive-readdir": "^2.2.2"
}
},
"type": "module"
}
12 changes: 7 additions & 5 deletions tools/proto2jsonschema/postgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

const path = require('path');
const fs = require('fs');
const recursive = require("recursive-readdir");
const protobufjs = require('protobufjs');
const flatten = require('flat');
import path from 'path';
import fs from 'fs';
import recursive from 'recursive-readdir';
import protobufjs from 'protobufjs';
import { flatten } from 'flat'

/**
* This tool polishes the JSON schemas with a few modifications:
Expand All @@ -27,6 +27,8 @@ const flatten = require('flat');
* - Adds "examples" - A list of paths to the test event data associated with the schema
* - e.g. ["https://googleapis.github.io/google-cloudevents/testdata/google/events/cloud/audit/v1/LogEntryData-pubsubCreateTopic.json"]
*/
const __filename = new URL(import.meta.url).pathname;
const __dirname = path.dirname(__filename);
const ROOT = path.resolve(`${__dirname}/../../jsonschema`);
const TESTDATA = path.resolve(`${__dirname}/../../testdata`);
console.log(`Fixing paths in dir: ${ROOT}`);
Expand Down

0 comments on commit 2f0c0ef

Please sign in to comment.