-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Support webpack 5.x by reading source from file-system
BREAKING CHANGE: HtmlRenderPlugin exported as named and default variable. commonjs require statements will need to be changed as follows: ```js // old const HtmlRenderPlugin = require('html-render-webpack-plugin'); // new const { HtmlRenderPlugin } = require('html-render-webpack-plugin'); ```
- Loading branch information
1 parent
edd758b
commit b83be46
Showing
45 changed files
with
2,772 additions
and
3,349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Release | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- alpha | ||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
- name: Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: yarn release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Test | ||
|
||
on: [push] | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-18.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
- name: Lint | ||
run: yarn lint | ||
- name: Test | ||
run: yarn test |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import evalutateFromSource from "./evalutateFromSource"; | ||
import { SourceModules, ExtraGlobals } from "./common-types"; | ||
import evaluateFromFileSystem from "./evaluateFromFileSystem"; | ||
import { FileSystem, ExtraGlobals } from "./common-types"; | ||
|
||
export = function createRenderer({ | ||
fileName, | ||
source, | ||
fileSystem, | ||
rootDir, | ||
extraGlobals, | ||
}: { | ||
fileName: string; | ||
source: SourceModules; | ||
fileSystem: FileSystem; | ||
extraGlobals: ExtraGlobals; | ||
rootDir: string; | ||
}) { | ||
if (!fileName) { | ||
throw new Error("Missing filename"); | ||
} | ||
if (!source) { | ||
if (!fileSystem) { | ||
throw new Error("Missing source"); | ||
} | ||
return evalutateFromSource(fileName, source, extraGlobals); | ||
if (!rootDir || typeof rootDir !== "string") { | ||
throw new Error(`Recieved rootDir as ${typeof rootDir}`); | ||
} | ||
return evaluateFromFileSystem(fileName, fileSystem, rootDir, extraGlobals); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import path from "path"; | ||
import evaluate from "eval"; | ||
import { ExtraGlobals, FileSystem } from "./common-types"; | ||
|
||
import { log } from "./logging"; | ||
|
||
function getFromSourceModules( | ||
specifier: string, | ||
fsModule: FileSystem, | ||
rootDir: string | ||
) { | ||
const sourceModuleSpecifier = specifier.replace(/^\.\//, ""); | ||
if (!fsModule.existsSync(path.resolve(rootDir, sourceModuleSpecifier))) { | ||
log( | ||
`Unable to find file specifier ${sourceModuleSpecifier}. Root: ${rootDir}.` | ||
); | ||
return undefined; | ||
} | ||
return fsModule.readFileSync(path.resolve(rootDir, sourceModuleSpecifier)); | ||
} | ||
|
||
function evaluateFromFileSystem( | ||
specifier: string, | ||
fsModule: FileSystem, | ||
rootDir: string, | ||
extraGlobals: ExtraGlobals | ||
) { | ||
log( | ||
`Evaluating source for ${specifier}". From root directory: "${rootDir}".` | ||
); | ||
let source; | ||
try { | ||
source = getFromSourceModules(specifier, fsModule, rootDir); | ||
} catch (error) { | ||
throw new Error(`An error reading "${specifier}". Error: ${error}`); | ||
} | ||
return evaluate( | ||
source, | ||
/* filename: */ specifier, | ||
/* scope: */ { | ||
console, | ||
process, | ||
...(extraGlobals || {}), | ||
require: createLinker(specifier, fsModule, rootDir, extraGlobals), | ||
}, | ||
/* includeGlobals: */ true | ||
); | ||
} | ||
|
||
function createLinker( | ||
parentModulePath: string, | ||
fsModule: FileSystem, | ||
rootDir: string, | ||
extraGlobals: ExtraGlobals | ||
) { | ||
log("Creating linker for", parentModulePath); | ||
return function linker(specifier: string) { | ||
const absPath = path.join(path.dirname(parentModulePath), specifier); | ||
if (!getFromSourceModules(specifier, fsModule, rootDir)) { | ||
log(`Using external require for ${specifier} from ${parentModulePath}`); | ||
return require(specifier); | ||
} | ||
log(`Linking ${parentModulePath} to asset ${specifier}`); | ||
return evaluateFromFileSystem(absPath, fsModule, rootDir, extraGlobals); | ||
}; | ||
} | ||
|
||
export = evaluateFromFileSystem; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.