Comments (10)
@fossamagna amazing, thanks again. I updated to v1.2.3 and it looks like its working perfectly, I am now able to delete all my globa.foo = foo
lines, thanks!
from gas-webpack-plugin.
Thanks for publishing this fix @fossamagna, this worked for me too, and appreciate you still supporting webpack 4.
from gas-webpack-plugin.
@alexblack Thank you.
Can I see your source codes (Or part of it) ?
ex: *.ts, tsconfig.json
...
from gas-webpack-plugin.
@fossamagna thank you! :)
As a starting point, my project is based off: https://github.com/enuchi/React-Google-Apps-Script
Does that help at all? I'll see if I can repro the problem on that project.
from gas-webpack-plugin.
Here is the tsconfig.json:
{
"compilerOptions":{
"esModuleInterop":true,
"forceConsistentCasingInFileNames":true,
"lib":[
"ES2019"
],
"module":"commonjs",
"strict":true,
"target":"es5",
"types":[
"gas-types-detailed",
"node"
]
}
}
And here is one of the .ts files who's exported functions I want attached to global for GAS
https://gist.github.com/alexblack/5bd0b55104c360306f5f95349460e765
from gas-webpack-plugin.
@alexblack Thank you.
I tried to reproduce, but can not do it.
Here is repository of used project.
https://github.com/fossamagna/gas-webpack-plugin-issue-561
Steps to reproduce:
- Clone https://github.com/enuchi/React-Google-Apps-Script
- Change gas-webpack-plugin version to 1.2.2 in package.json
- Modify webpack.config.json (Add autoGlobalExportsFiles option)
- Replace src/server/sheets.js to your sheet.ts
- Modify sheet.ts (fix to error of TypeScript build. Comment out function return type)
- Modify tsconfig.json (base on your tsconfig.json)
- Comment out expressons of assignment to global object in src/server/index.js.
- npm install && npm run build
The result of build was as follows.
dist/code.js
function API_ERROR(message) {}
function setActiveSheet(sheetName) {}
function getSheets() {}
function setActiveSheetId(sheetId) {}
function getSpreadsheetValues(range) {}
function getSpreadsheetNamedRanges() {}
function getSpreadsheetSheetsAndNamedRanges() {}
function markSpreadsheetInstalledOn() {}
function getSpreadsheetProperties() {}
!function(e, a) {
for (var i in a) e[i] = a[i];
}(this, function(modules) {
var installedModules = {};
function __webpack_require__(moduleId) {
if (installedModules[moduleId]) return installedModules[moduleId].exports;
var module = installedModules[moduleId] = {
i: moduleId,
l: !1,
exports: {}
};
return modules[moduleId].call(module.exports, module, module.exports, __webpack_require__),
module.l = !0, module.exports;
}
return __webpack_require__.m = modules, __webpack_require__.c = installedModules,
__webpack_require__.d = function(exports, name, getter) {
__webpack_require__.o(exports, name) || Object.defineProperty(exports, name, {
enumerable: !0,
get: getter
});
}, __webpack_require__.r = function(exports) {
"undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(exports, Symbol.toStringTag, {
value: "Module"
}), Object.defineProperty(exports, "__esModule", {
value: !0
});
}, __webpack_require__.t = function(value, mode) {
if (1 & mode && (value = __webpack_require__(value)), 8 & mode) return value;
if (4 & mode && "object" == typeof value && value && value.__esModule) return value;
var ns = Object.create(null);
if (__webpack_require__.r(ns), Object.defineProperty(ns, "default", {
enumerable: !0,
value: value
}), 2 & mode && "string" != typeof value) for (var key in value) __webpack_require__.d(ns, key, function(key) {
return value[key];
}.bind(null, key));
return ns;
}, __webpack_require__.n = function(module) {
var getter = module && module.__esModule ? function() {
return module["default"];
} : function() {
return module;
};
return __webpack_require__.d(getter, "a", getter), getter;
}, __webpack_require__.o = function(object, property) {
return Object.prototype.hasOwnProperty.call(object, property);
}, __webpack_require__.p = "", __webpack_require__(__webpack_require__.s = 1);
}([ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.API_ERROR = exports.getSpreadsheetProperties = exports.markSpreadsheetInstalledOn = exports.getSpreadsheetSheetsAndNamedRanges = exports.getSpreadsheetNamedRanges = exports.getSpreadsheetValues = exports.setActiveSheetId = exports.getSheets = exports.setActiveSheet = void 0;
exports.setActiveSheet = function(sheetName) {
SpreadsheetApp.getActive().getSheetByName(sheetName).activate();
}, exports.getSheets = function() {
return SpreadsheetApp.getActive().getSheets().map((function(s) {
return {
name: s.getName(),
hidden: s.isSheetHidden()
};
}));
}, exports.setActiveSheetId = function(sheetId) {
for (var sheets = SpreadsheetApp.getActive().getSheets(), i = 0; i < sheets.length; i += 1) if (sheets[i].getSheetId() === sheetId) return void sheets[i].activate();
}, exports.getSpreadsheetValues = function(range) {
return SpreadsheetApp.getActive().getRange(range).getDisplayValues();
}, exports.getSpreadsheetNamedRanges = function() {
return SpreadsheetApp.getActive().getNamedRanges().map((function(nr) {
return {
name: nr.getName()
};
}));
}, exports.getSpreadsheetSheetsAndNamedRanges = function() {
return {
namedRanges: exports.getSpreadsheetNamedRanges(),
sheets: exports.getSheets()
};
};
var findMetadataByKey = function(key) {
for (var metadatas = SpreadsheetApp.getActive().getDeveloperMetadata(), i = 0; i < metadatas.length; i += 1) {
var m = metadatas[i];
if (m.getKey() === key) return m;
}
return null;
};
exports.markSpreadsheetInstalledOn = function() {
SpreadsheetApp.getActive().addDeveloperMetadata("originalSpreadsheetId", SpreadsheetApp.getActive().getId());
var date = new Date;
SpreadsheetApp.getActive().addDeveloperMetadata("installedOn", date.valueOf().toString());
};
exports.getSpreadsheetProperties = function() {
var metadata;
return {
id: SpreadsheetApp.getActive().getId(),
timezone: SpreadsheetApp.getActive().getSpreadsheetTimeZone(),
originalSpreadsheetId: (metadata = findMetadataByKey("originalSpreadsheetId")) ? metadata.getValue() : null,
installedOnTimestamp: function() {
var metadata = findMetadataByKey("installedOn");
if (!metadata) return null;
var timestampStr = metadata.getValue();
return parseFloat(timestampStr);
}()
};
}, exports.API_ERROR = function(message) {
throw new Error(message);
}, global.API_ERROR = exports.API_ERROR, global.setActiveSheet = exports.setActiveSheet,
global.getSheets = exports.getSheets, global.setActiveSheetId = exports.setActiveSheetId,
global.getSpreadsheetValues = exports.getSpreadsheetValues, global.getSpreadsheetNamedRanges = exports.getSpreadsheetNamedRanges,
global.getSpreadsheetSheetsAndNamedRanges = exports.getSpreadsheetSheetsAndNamedRanges,
global.markSpreadsheetInstalledOn = exports.markSpreadsheetInstalledOn, global.getSpreadsheetProperties = exports.getSpreadsheetProperties;
}, function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
__webpack_require__(0);
} ]));
Maybe there will be anything difference to your actual project.
Can I see your repository of actual project ?
from gas-webpack-plugin.
Hi @fossamagna thanks for working through that. I think actually the problem does reproduce in your steps. If you view the output file, dist/code.js, you can see its similar to the one I posted that has the problem. The difference I see is that the one that works wraps some of the code with (function(global) {
but the non-working one does not.
To fully reproduce the problem:
- I cloned the repo you made
- I added a bit of code (below) to the sheets.ts to try to get an add-on menu item to show up
- I followed the repo setup instructions
- I ran
yarn start
, and opened the spreadsheet (that the setup instructions created)
Expected results: My addon should show up in the sheets addon menu.
Actual results: My addon does not show up in the menu, and I see an error about global
in the console.
Additional code to add the menu item:
export const onOpen = (e?: GoogleAppsScript.Events.SheetsOnOpen) => {
SpreadsheetApp.getUi()
.createAddonMenu()
.addItem('Test', 'openSidebar')
.addToUi();
};
export const onInstall = () => {
onOpen();
};
Error in the console:
Google Apps Script: ReferenceError: global is not defined
from gas-webpack-plugin.
@alexblack Thanks to your steps of fully reproduce, I could reproduce this issue!
The cause is no pass global object by webpack when use autoGlobalExportsFiles option.
It will take time for us to resolve a root of this issue.
But, I can release patch release, and it will works well.
from gas-webpack-plugin.
@alexblack Thanks to your steps of fully reproduce, I could reproduce this issue!
The cause is no pass global object by webpack when use autoGlobalExportsFiles option.
It will take time for us to resolve a root of this issue.
But, I can release patch release, and it will works well.
Thats great news! Thanks again, I really appreciate your plugin, and I'm excited to be able to use autoGlobalExportsFiles
so we don't have to keep manually adding our functions to global.
from gas-webpack-plugin.
@alexblack Hi, I published v1.2.3 (for webpack4) and v2.0.2 (for webpack5). Please try it.
from gas-webpack-plugin.
Related Issues (20)
- ERROR in chunk main [entry] HOT 6
- Does your script support classes HOT 3
- Production mode HOT 6
- Webpack-cli required
- Property accessors doesn't work.
- Cannot read property 'getChunkModules' of undefined HOT 3
- Question - Automatically generating a typescript interface for the global functions HOT 29
- Remove JS Doc comments from custom function defintion
- README: `Script function not found: doGet` - special requirements for gas-webapps? HOT 12
- Use GitHub Actions
- Fails to parse access to import.meta HOT 2
- GasPlugin cannot be used with decorators HOT 6
- add `include` option in order to define path patterns to detect functions
- Default includePatterns broken in v2.2.0 HOT 2
- Error ReferenceError: module is not defined (anonymous) @ echo:gs.1 HOT 4
- Compiler errors with autoGlobalExportsFiles and webpack 5 HOT 11
- `autoGlobalExportsFiles` not working with ECMAScript HOT 5
- named export of a `const` function inside the declaration isn't exported to global
- `autoGlobalExportsFiles` options does not work HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gas-webpack-plugin.