gas-webpack-plugin
Advanced tools
Comparing version 2.5.0 to 2.6.0
@@ -0,1 +1,10 @@ | ||
# [2.6.0](https://github.com/fossamagna/gas-webpack-plugin/compare/v2.5.0...v2.6.0) (2024-05-23) | ||
### Features | ||
* detect export function if autoGlobalExportsFiles is enabled ([#909](https://github.com/fossamagna/gas-webpack-plugin/issues/909)) ([99925f6](https://github.com/fossamagna/gas-webpack-plugin/commit/99925f67bd15c6e61db1054dc3ada4b31869cd48)) | ||
# [2.5.0](https://github.com/fossamagna/gas-webpack-plugin/compare/v2.4.0...v2.5.0) (2023-04-25) | ||
@@ -2,0 +11,0 @@ |
89
index.js
@@ -1,8 +0,8 @@ | ||
'use strict'; | ||
"use strict"; | ||
const { generate } = require('gas-entry-generator'); | ||
const { SourceMapSource, RawSource } = require('webpack-sources'); | ||
const { RuntimeGlobals, Dependency } = require('webpack'); | ||
const minimatch = require('minimatch'); | ||
const path = require('path'); | ||
const { generate } = require("gas-entry-generator"); | ||
const { SourceMapSource, RawSource } = require("webpack-sources"); | ||
const { RuntimeGlobals, Dependency } = require("webpack"); | ||
const { minimatch } = require("minimatch"); | ||
const path = require("path"); | ||
const slash = require("slash"); | ||
@@ -13,3 +13,3 @@ | ||
autoGlobalExportsFiles: [], | ||
include: ["**/*"] | ||
include: ["**/*"], | ||
}; | ||
@@ -27,20 +27,22 @@ | ||
source = sourceAndMap.source; | ||
map = sourceAndMap.map | ||
map = sourceAndMap.map; | ||
} else { | ||
source = asset.source(); | ||
map = typeof asset.map === 'function' | ||
? asset.map() | ||
: null | ||
map = typeof asset.map === "function" ? asset.map() : null; | ||
} | ||
const entries = compilation.chunkGraph.getChunkModules(chunk) | ||
.filter(module => !!entryFunctions.get(module.rootModule || module)) | ||
.map(module => entryFunctions.get(module.rootModule || module).entryPointFunctions) | ||
.filter(entries => !!entries) | ||
.join('\n'); | ||
const entries = compilation.chunkGraph | ||
.getChunkModules(chunk) | ||
.filter((module) => !!entryFunctions.get(module.rootModule || module)) | ||
.map( | ||
(module) => | ||
entryFunctions.get(module.rootModule || module).entryPointFunctions | ||
) | ||
.filter((entries) => !!entries) | ||
.join("\n"); | ||
const gasify = entries + source; | ||
compilation.assets[filename] = map | ||
? new SourceMapSource(gasify, filename, map) | ||
: new RawSource(gasify); | ||
? new SourceMapSource(gasify, filename, map) | ||
: new RawSource(gasify); | ||
} | ||
@@ -69,3 +71,5 @@ | ||
const module = dep.m; | ||
if (!this.includePatterns.some(file => this.match(module.resource, file))) { | ||
if ( | ||
!this.includePatterns.some((file) => this.match(module.resource, file)) | ||
) { | ||
return; | ||
@@ -75,3 +79,7 @@ } | ||
comment: this.comment, | ||
autoGlobalExports: module.resource && this.autoGlobalExportsFilePatterns.some(file => this.match(module.resource, file)), | ||
autoGlobalExports: | ||
module.resource && | ||
this.autoGlobalExportsFilePatterns.some((file) => | ||
this.match(module.resource, file) | ||
), | ||
exportsIdentifierName: RuntimeGlobals.exports, | ||
@@ -81,5 +89,6 @@ globalIdentifierName: RuntimeGlobals.global, | ||
const originalSource = typeof source.original === 'function' | ||
? source.original().source() | ||
: source.source(); | ||
const originalSource = | ||
typeof source.original === "function" | ||
? source.original().source() | ||
: source.source(); | ||
@@ -94,10 +103,12 @@ const output = generate(originalSource, options); | ||
GasPlugin.prototype.apply = function(compiler) { | ||
GasPlugin.prototype.apply = function (compiler) { | ||
const context = compiler.options.context; | ||
const autoGlobalExportsFilePatterns = this.options.autoGlobalExportsFiles | ||
.map(file => path.isAbsolute(file) ? file : path.resolve(context, file)); | ||
const includePatterns = this.options.include | ||
.map(file => path.isAbsolute(file) ? file : path.resolve(context, file)); | ||
const autoGlobalExportsFilePatterns = this.options.autoGlobalExportsFiles.map( | ||
(file) => (path.isAbsolute(file) ? file : path.resolve(context, file)) | ||
); | ||
const includePatterns = this.options.include.map((file) => | ||
path.isAbsolute(file) ? file : path.resolve(context, file) | ||
); | ||
const plugin = { name: 'GasPlugin' }; | ||
const plugin = { name: "GasPlugin" }; | ||
const compilationHook = (compilation, { normalModuleFactory }) => { | ||
@@ -110,10 +121,9 @@ const gasDependencyTemplate = new GasDependency.Template({ | ||
compilation.dependencyTemplates.set( | ||
GasDependency, | ||
gasDependencyTemplate | ||
); | ||
compilation.dependencyTemplates.set(GasDependency, gasDependencyTemplate); | ||
const handler = parser => { | ||
const handler = (parser) => { | ||
parser.hooks.program.tap(plugin, () => { | ||
parser.state.current.addDependency(new GasDependency(parser.state.current)); | ||
parser.state.current.addDependency( | ||
new GasDependency(parser.state.current) | ||
); | ||
}); | ||
@@ -133,3 +143,8 @@ }; | ||
compilation.hooks.chunkAsset.tap(plugin, (chunk, filename) => { | ||
gasify(compilation, chunk, filename, gasDependencyTemplate.entryFunctions) | ||
gasify( | ||
compilation, | ||
chunk, | ||
filename, | ||
gasDependencyTemplate.entryFunctions | ||
); | ||
}); | ||
@@ -136,0 +151,0 @@ |
{ | ||
"name": "gas-webpack-plugin", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"description": "Webpack Plugin for Google Apps Script", | ||
@@ -8,4 +8,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"gas-entry-generator": "2.5.1", | ||
"minimatch": "^7.4.2", | ||
"gas-entry-generator": "2.6.0", | ||
"minimatch": "^9.0.0", | ||
"slash": "^3.0.0", | ||
@@ -15,8 +15,10 @@ "webpack-sources": "^3.1.1" | ||
"devDependencies": { | ||
"conventional-changelog-cli": "^2.0.1", | ||
"@eslint/js": "^9.1.1", | ||
"conventional-changelog-cli": "^4.1.0", | ||
"es3ify-webpack-plugin": "^0.1.0", | ||
"eslint": "8.39.0", | ||
"eslint": "9.2.0", | ||
"globals": "^15.0.0", | ||
"memory-fs": "0.5.0", | ||
"nyc": "15.1.0", | ||
"tap": "16.3.4", | ||
"tap": "16.3.10", | ||
"ts-loader": "^9.1.1", | ||
@@ -28,3 +30,4 @@ "typescript": "^5.0.4", | ||
"pretest": "cd test && npm install", | ||
"test": "eslint index.js && nyc --reporter=lcov --reporter=text-summary tap test/*.test.js", | ||
"lint": "eslint index.js", | ||
"test": "nyc --reporter=lcov --reporter=text-summary tap test/*.test.js", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", | ||
@@ -31,0 +34,0 @@ "version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md" |
const webpack = require("webpack"); | ||
const MemoryFS = require("memory-fs"); | ||
const test = require('tap').test; | ||
const GasPlugin = require('../'); | ||
const es3ifyPlugin = require('es3ify-webpack-plugin'); | ||
const test = require("tap").test; | ||
const GasPlugin = require("../"); | ||
const es3ifyPlugin = require("es3ify-webpack-plugin"); | ||
const options = { | ||
mode: 'none', | ||
devtool: 'source-map', | ||
context: __dirname + '/fixtures-fix-411', | ||
mode: "none", | ||
devtool: "source-map", | ||
context: __dirname + "/fixtures-fix-411", | ||
entry: "./main.ts", | ||
@@ -16,3 +16,3 @@ module: { | ||
test: /(\.ts)$/, | ||
loader: 'ts-loader', | ||
loader: "ts-loader", | ||
}, | ||
@@ -30,21 +30,20 @@ ], | ||
new GasPlugin({ | ||
autoGlobalExportsFiles: ['*.ts'] | ||
autoGlobalExportsFiles: ["*.ts"], | ||
}), | ||
new es3ifyPlugin() | ||
], | ||
optimization: { | ||
minimize: false | ||
} | ||
minimize: false, | ||
}, | ||
}; | ||
test('gas-plugin with es3ify', function(t) { | ||
test("gas-plugin with es3ify", function (t) { | ||
const compiler = webpack(options); | ||
const mfs = new MemoryFS(); | ||
compiler.outputFileSystem = mfs; | ||
compiler.run(function(err, stats) { | ||
t.error(err, 'build failed'); | ||
compiler.run(function (err, stats) { | ||
t.error(err, "build failed"); | ||
const jsonStats = stats.toJson(); | ||
t.ok(jsonStats.errors.length === 0); | ||
t.ok(jsonStats.warnings.length === 0); | ||
const bundle = mfs.readFileSync(__dirname + '/output/bundle.js', 'utf8'); | ||
const bundle = mfs.readFileSync(__dirname + "/output/bundle.js", "utf8"); | ||
const output = `/** | ||
@@ -59,6 +58,11 @@ * Return write arguments. | ||
} | ||
function boo() { | ||
} | ||
function foo() { | ||
}` | ||
}`; | ||
t.ok(bundle.replace(/\r\n/g, "\n").startsWith(output), bundle); | ||
t.match(bundle, /.*__webpack_require__\.g\.foo = __webpack_exports__\.foo;.*/); | ||
t.match( | ||
bundle.toString(), | ||
/.*__webpack_require__\.g\.foo = __webpack_exports__\.foo;.*/ | ||
); | ||
t.end(); | ||
@@ -68,3 +72,3 @@ }); | ||
test('gas-plugin with es3ify prepend top-level functions when minimize is enabled', function(t) { | ||
test("gas-plugin with es3ify prepend top-level functions when minimize is enabled", function (t) { | ||
options.optimization.minimize = true; | ||
@@ -74,9 +78,10 @@ const compiler = webpack(options); | ||
compiler.outputFileSystem = mfs; | ||
compiler.run(function(err, stats) { | ||
t.error(err, 'build failed'); | ||
compiler.run(function (err, stats) { | ||
t.error(err, "build failed"); | ||
const jsonStats = stats.toJson(); | ||
t.ok(jsonStats.errors.length === 0); | ||
t.ok(jsonStats.warnings.length === 0); | ||
const bundle = mfs.readFileSync(__dirname + '/output/bundle.js', 'utf8'); | ||
const output = 'function echo(){}function plus(){}function minus(){}function foo(){}' | ||
const bundle = mfs.readFileSync(__dirname + "/output/bundle.js", "utf8"); | ||
const output = | ||
"function echo(){}function plus(){}function minus(){}function boo(){}function foo(){}"; | ||
t.ok(bundle.startsWith(output), bundle); | ||
@@ -83,0 +88,0 @@ t.match(bundle, /.*\.g\.foo=.+\.foo.*/); |
@@ -1,2 +0,2 @@ | ||
import echo from './echo'; | ||
import echo from "./echo"; | ||
/** | ||
@@ -13,2 +13,3 @@ * Return write arguments. | ||
} | ||
global.plus = plus, global.minus = minus; | ||
(global.plus = plus), (global.minus = minus); | ||
export function boo() {} |
@@ -7,4 +7,4 @@ { | ||
// "incremental": true, /* Enable incremental compilation */ | ||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ | ||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ | ||
"target": "ESNext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */, | ||
"module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */, | ||
// "lib": [], /* Specify library files to be included in the compilation. */ | ||
@@ -16,3 +16,3 @@ // "allowJs": true, /* Allow javascript files to be compiled. */ | ||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ | ||
"sourceMap": true, /* Generates corresponding '.map' file. */ | ||
"sourceMap": true /* Generates corresponding '.map' file. */, | ||
// "outFile": "./", /* Concatenate and emit output to single file. */ | ||
@@ -30,3 +30,3 @@ // "outDir": "./", /* Redirect output structure to the directory. */ | ||
/* Strict Type-Checking Options */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
"strict": true /* Enable all strict type-checking options. */, | ||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ | ||
@@ -54,3 +54,3 @@ // "strictNullChecks": true, /* Enable strict null checks. */ | ||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ | ||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ | ||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, | ||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ | ||
@@ -70,6 +70,6 @@ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ | ||
/* Advanced Options */ | ||
"skipLibCheck": true, /* Skip type checking of declaration files. */ | ||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ | ||
"skipLibCheck": true /* Skip type checking of declaration files. */, | ||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ | ||
}, | ||
"include": ["./**/*"] | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93925
1853
11
+ Addedescodegen@2.1.0(transitive)
+ Addedesprima-next@6.0.3(transitive)
+ Addedgas-entry-generator@2.6.0(transitive)
+ Addedminimatch@9.0.5(transitive)
- Removeddeep-is@0.1.4(transitive)
- Removedescodegen@2.0.0(transitive)
- Removedesprima-next@5.8.4(transitive)
- Removedfast-levenshtein@2.0.6(transitive)
- Removedgas-entry-generator@2.5.1(transitive)
- Removedlevn@0.3.0(transitive)
- Removedminimatch@7.4.6(transitive)
- Removedoptionator@0.8.3(transitive)
- Removedprelude-ls@1.1.2(transitive)
- Removedtype-check@0.3.2(transitive)
- Removedword-wrap@1.2.5(transitive)
Updatedgas-entry-generator@2.6.0
Updatedminimatch@^9.0.0