Skip to content

Commit

Permalink
fix nodejs 12 issues with promises library
Browse files Browse the repository at this point in the history
  • Loading branch information
tm1000 committed Apr 14, 2022
1 parent 0f93c8c commit 35f4963
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
15 changes: 10 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.1.1] - 2022-04-14

### Fixed

- Fixed issues with nodejs 12 and promises

## [2.1.0] - 2022-04-14

### Added

- Offical Support for hooks in service worker to reload extension during

## [2.0.4] - 2022-04-11

### Fixed
Expand All @@ -33,11 +43,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Publish fixes for github

## [2.0.0] - 2022-04-05

### Added

- Offical Support for hooks in service worker to reload extension during development

### Added

- Typescript support
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webextension-toolbox/webpack-webextension-plugin",
"version": "2.1.0",
"version": "2.1.1",
"description": "Webpack plugin that compiles web-extension manifest.json files and adds smart auto reload",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
25 changes: 21 additions & 4 deletions src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import WebSocket from "ws";
import webpack, { Compiler, Compilation, Stats } from "webpack";
import Mustache from "mustache";
import Ajv from "ajv";
import fs from "fs/promises";
import { constants, readFileSync } from "fs";
import fs, { constants, readFileSync } from "fs";
import vendors from "./vendors.json";
import manifestSchema from "./manifest.schema.json";

// TODO: Remove when we drop support for Node 12, See https://github.com/nodejs/node/issues/35740
const { access } = fs.promises;

const { WebpackError } = webpack;
interface ManifestObject {
[key: string]: any;
Expand Down Expand Up @@ -539,6 +541,10 @@ export default class WebextensionPlugin {

/**
* Add Background Script to reload extension in dev mode
*
* @param manifest browser._manifest.WebExtensionManifest
* @param compilation Compilation
* @returns Promise<browser._manifest.WebExtensionManifest>
*/
async addBackgroundscript(
manifest: browser._manifest.WebExtensionManifest,
Expand Down Expand Up @@ -598,15 +604,26 @@ export default class WebextensionPlugin {
return manifest;
}

async fileExists(file: string) {
/**
* Check if file exists
* @param file
* @returns Promise<boolean>
*/
async fileExists(file: string): Promise<boolean> {
try {
await fs.access(file, constants.F_OK);
await access(file, constants.F_OK);
return true;
} catch {
return false;
}
}

/**
* Get the true filename (used for Typescript detections)
* @param context
* @param relative
* @returns Promise<string>
*/
async getTrueFilename(context: string, relative: string): Promise<string> {
const { name, dir } = path.parse(relative);
if (await this.fileExists(path.join(context, dir, `${name}.js`))) {
Expand Down

0 comments on commit 35f4963

Please sign in to comment.