Closed troogyt closed 1 year ago
The bundle.sh
script assumes that a dist
folder already exists from a previous build. This is a mistake and needs to be fixed.
As a workaround, you can try just creating an empty folder called dist
in the root of the project folder and running the script again.
Edit: although, it continues, which does confuse me quite a lot right now (I just woke up; Dont bash scripts usually stop at an error?) -
You also need to install the zip
command in your WSL sub-system.
Edit 2: (Gosh I am too tired) The syntax error seems to be in the Typescript code itself - I'd need to investigate further to understand that error
Yeah, I installed zip but it still failed. I'll try creating the empty dist
folder as you say. But yes, it appears there is a syntax error where there is a "??" in the typescript file, which I think is imported and not yours.
One other thing, as I understand the bundle.sh script, it appears to want to create a zip file, but the extensions in the Thunderbird/extensions directory are .xpi files. I know these are a form of zip and I can open them in 7zip, but not sure how this bundle script will create the .xpi to drop into TB/extensions folder.
Took a lot of searching to find this page that even mentions the nullish coalescing operator: (https://stackoverflow.com/questions/68692038/how-to-solve-error-syntaxerror-unexpected-token).
It looks like that is what has been used here.
So, as I understand it, this:
let i = startIndex ?? 42;
effectively means:
let i equal startIndex unless it is NULL or UNDEFINED, in which case let it equal 42
There are many instances of the ??
operator in the tsc.js file, but here are just the first few lines:
$cat -b /mnt/c/Users/USERNAME/Downloads/Software/Thunderbird/Extensions/thundersort-1.1.0/node_modules/typescript/lib/tsc.js | grep ??
87 for (let i = startIndex ?? 0; i < array.length; i++) {
98 for (let i = startIndex ?? array.length - 1; i >= 0; i--) {
109 for (let i = startIndex ?? 0; i < array.length; i++) {
119 for (let i = startIndex ?? array.length - 1; i >= 0; i--) {
...
Due to the precedence of the ??
operator I wonder if adding parentheses might fix it:
for (let i = (startIndex ?? 0); i < array.length; i++) {
Is it possible that you are running an older NodeJS version, that doesn't support the ??
operator?
Yeah, I installed zip but it still failed. I'll try creating the empty
dist
folder as you say. But yes, it appears there is a syntax error where there is a "??" in the typescript file, which I think is imported and not yours.One other thing, as I understand the bundle.sh script, it appears to want to create a zip file, but the extensions in the Thunderbird/extensions directory are .xpi files. I know these are a form of zip and I can open them in 7zip, but not sure how this bundle script will create the .xpi to drop into TB/extensions folder.
To create a xpi, simply rename the resulting zip to end with .xpi
- I dunno why the script doesn't do that on it's own
Is it possible that you are running an older NodeJS version, that doesn't support the
??
operator?
Well ok...so, I only installed npm specifically for this. and it appears to have installed nodejs version v12.22.9
as a dependency. The npm version is 8.5.1
. It looks like ??
requires v14+...
Yeah, I installed zip but it still failed. I'll try creating the empty
dist
folder as you say. But yes, it appears there is a syntax error where there is a "??" in the typescript file, which I think is imported and not yours. One other thing, as I understand the bundle.sh script, it appears to want to create a zip file, but the extensions in the Thunderbird/extensions directory are .xpi files. I know these are a form of zip and I can open them in 7zip, but not sure how this bundle script will create the .xpi to drop into TB/extensions folder.To create a xpi, simply rename the resulting zip to end with
.xpi
- I dunno why the script doesn't do that on it's own
Would changing bundle.sh
from:
zip -qqr thundersort.zip README.md LICENSE manifest.json package.json package-lock.json tsconfig.json src dist
to:
zip -qqr thundersort.xpi README.md LICENSE manifest.json package.json package-lock.json tsconfig.json src dist
?
Would changing
bundle.sh
from:zip -qqr thundersort.zip README.md LICENSE manifest.json package.json package-lock.json tsconfig.json src dist
to:zip -qqr thundersort.xpi README.md LICENSE manifest.json package.json package-lock.json tsconfig.json src dist
?
I believe that should work - However, I am not all too invested in the topic of xpi files, nor do I know if the zip command cares about the file ending or not. For now, you can simply rename the resulting file.
Well ok...so, I only installed npm specifically for this. and it appears to have installed nodejs version
v12.22.9
as a dependency. The npm version is8.5.1
. It looks like??
requires v14+...
You should be able to install a newer version of NPM and Node as per official instructions. I cannot assist you much more than this, as there are many ways to install npm/node and I am currently not anywhere near my PC.
Would changing
bundle.sh
from:zip -qqr thundersort.zip README.md LICENSE manifest.json package.json package-lock.json tsconfig.json src dist
to:zip -qqr thundersort.xpi README.md LICENSE manifest.json package.json package-lock.json tsconfig.json src dist
?I believe that should work - However, I am not all too invested in the topic of xpi files, nor do I know if the zip command cares about the file ending or not. For now, you can simply rename the resulting file.
Well ok...so, I only installed npm specifically for this. and it appears to have installed nodejs version
v12.22.9
as a dependency. The npm version is8.5.1
. It looks like??
requires v14+...You should be able to install a newer version of NPM and Node as per official instructions. I cannot assist you much more than this, as there are many ways to install npm/node and I am currently not anywhere near my PC.
node and npm upgraded (took a bit of forced overwriting). npm run bundle
now works and changing the extension in the bundle.sh has produced thundersort.xpi
instead of thundersort.zip
.
This may be my system but not sure. I tried building the add-on as suggested, but it fails with the following error (after running 'sudo apt install npm' first to install npm):
`$npm run bundle
rm: cannot remove 'dist': No such file or directory /mnt/c/Users/USERNAME/Downloads/Software/Thunderbird/Extensions/thundersort-1.1.0/node_modules/typescript/lib/tsc.js:93 for (let i = startIndex ?? 0; i < array.length; i++) { ^
SyntaxError: Unexpected token '?' at wrapSafe (internal/modules/cjs/loader.js:915:16) at Module._compile (internal/modules/cjs/loader.js:963:27) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) at Object. (/mnt/c/Users/USERNAME/Downloads/Software/Thunderbird/Extensions/thundersort-1.1.0/node_modules/typescript/bin/tsc:2:1)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
cp: target 'dist/' is not a directory
rm: cannot remove 'thundersort.zip': No such file or directory
./bundle.sh: line 7: zip: command not found
`
I am running it in WSL (ubuntu winux) from within the '/mnt/c/Users/USERNAME/Downloads/Software/Thunderbird/Extensions/thundersort-1.1.0' directory, I am wondering if running 'sudo apt install npm' whilst in the same directory has anything to do with it? (Except that looks like a syntax error above.)