Error trying to create sourcemap with grunt-contrib-uglify - angularjs

I'm attempting to add sourcemaps for an AngularJS application derived from the ngBoilerplate template, which uses grunt to build and grunt-contrib-uglify to minify the JavaScript sources into one app.js file.
The problem is that grunt can't actually write the sourcemap to disk, with this cryptic error (used grunt --verbose, edited only slightly):
Running "uglify" task
Running "uglify:compile" (uglify) task
Verifying property uglify.compile exists in config...OK
Files: release/assets/MyApp-1.0.0.debug.js -> release/assets/MyApp-1.0.0.js
Options: banner="", footer="", compress={"warnings":false}, mangle={}, beautify=false, report="min", expression=false, sourceMap
Minifying with UglifyJS...Reading release/assets/MyApp-1.0.0.debug.js...OK
OK
Writing release/assets/MyApp-1.0.0.js...OK
Writing release/assets/MyApp-1.0.0.js.map...ERROR
Warning: Unable to write "release/assets/MyApp-1.0.0.map" file (Error code: undefined). Use --force to continue.
Aborted due to warnings.
The critical section being:
Warning: Unable to write "release/assets/MyApp-1.0.0.map" file (Error code: undefined). Use --force to continue.
Now you may be tempted to say this is a duplicate of the question Grunt Uglify source map “unable to write” except that case was a simple gotcha where the asker was using a new configuration style with an older version of the package, resulting in the error Unable to write "true" file. Not so in my case. It's pretty clear that the file name it is attempting to write is correct (the JS file plus the ".map" extension) but that the system can't do it and gives a colossally unhelpful "Error code: undefined" back.
Versions from the packages.json file - and I cleaned out the node_modules folder and re-ran npm install to make sure this is what was in use:
"devDependencies": {
"grunt": "0.4.5",
"grunt-recess": "0.6.1",
"grunt-contrib-jshint": "0.10.0",
"grunt-contrib-concat": "0.4.0",
"grunt-contrib-watch": "0.6.1",
"grunt-contrib-uglify": "0.5.0",
"grunt-karma": "0.6.2",
"grunt-ngmin-with-comments": "0.0.3",
"grunt-html2js": "0.2.3",
"grunt-groundskeeper": "0.1.9",
"lodash": "2.4.1",
"grunt-contrib-clean": "0.5.0",
"grunt-contrib-copy": "0.5.0",
"grunt-contrib-connect": "^0.7.1"
}
Inside node_modules, the uglify-js version is 2.4.14.
My Gruntfile config isn't exactly boilerplate ngBoilerplate - I've modified it some so that I can get a .debug.js that is unminified and a .js that is minified. Here it is:
uglify: {
compile: {
options: {
sourceMap: true
},
files: {
'<%= minJs %>': '<%= debugJs %>'
}
}
}
I have also tried:
specifying the sourceMapName property
As a string
As a function that takes the jsName and appends '.map' to it
As a function that does not try to write in the release/assets subdirectory
Not using the grunt templates and specifying the filenames for minJs and debugJs explicitly.
Nothing has worked. Any ideas?

I'm getting the same error with a different setup. Everything goes fine if I disable sourcemaps. I spent a couple hours debugging the error and gave up.
Just switch to an older version of grunt-contrib-uglify such as ~0.4 until they sort out what is wrong.

Related

How to set graphql-codegen documents file?

I have graphql-codegen.yml file and src folder under project root path.
graphql-codegen.yml
schema: "https://swapi-graphql.netlify.app/.netlify/functions/index"
overwrite: true
documents: "src/**/*.graphql"
generates:
src/generated/graphql-types.tsx:
plugins:
— "typescript"
— "typescript-operations"
— "typescript-react-apollo"
src/graphql/getAllPeople.graphql
query GetAllPeople($pageSize: Int) {
allPeople(first: $pageSize) {
people {
name
birthYear
gender
height
}
}
}
package.json
"scripts": {
"graphql:codegen": "graphql-codegen — config graphql-codegen.yml"
},
"dependencies": {
"#apollo/client": "^3.7.0",
"#emotion/core": "^10.0.21",
"#graphql-codegen/cli": "^2.16.2",
"#graphql-codegen/fragment-matcher": "^3.3.3",
"#graphql-codegen/typescript": "^2.8.6",
"#graphql-codegen/typescript-operations": "^2.5.11",
"#graphql-codegen/typescript-react-apollo": "^3.3.7"
},
When I type command yarn graphql:codegen on terminal, it shows error:
yarn run v1.22.17
$ graphql-codegen — config graphql-codegen.yml
Unable to find Codegen config file!
Please make sure that you have a configuration file under the current directory!
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
What's wrong with the setting ?

Husky and Git Hooks Guards not respected in IDEs

I have husky and lint-staged setup in a repository I am a main contributor to, and these guards consist of ensuring correct commitlint messages, proper branch naming patterns, and checking for linting errors on all commits.
This all works great when creating/committing/pushing branches from the command line, but when using any IDE's integrated Git UI, the checks are completely ignored, and anything can make it to the repo (incorrect commit messages, incorrect branch names, linting errors, etc.). Not sure why, nor do I know how to avoid this.
Here are some of the relevant pieces of code that is within this web of guards (obviously with irrelevant code omitted for clarity):
package.json:
"scripts": {
"lint": "eslint app/"
},
"devDependencies": {
"#commitlint/cli": "^16.2.3",
"#commitlint/config-conventional": "^16.2.1",
"enforce-branch-name": "^1.0.1"
},
...
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
"pre-push": "enforce-branch-name '^(branch-name-regex-rules)$'"
}
},
"lint-staged": {
"*.js": "npm run lint"
}
And then I have my .husky folder at the project root, with my commit-msg, pre-commit, and pre-push hook scripts:
commit-msg:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no -- commitlint --edit $1
pre-commit:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
pre-push:
#!/bin/sh
LC_ALL=C
local_branch="$(git rev-parse --abbrev-ref HEAD)"
valid_branch_regex="^(branch-name-regex-rules)$"
message="Error message for incorrect branch naming"
if [[ ! $local_branch =~ $valid_branch_regex ]]
then
echo "$message"
exit 1
fi
exit 0
I think that should cover all the relevant code pieces that I have. Like I said, when using the command line to make commits and push branches to the remote, these rules come into play and work, informing developers of incorrect patterns.
But any developer that uses like, VSCode's integrated Git feature to commit and/or push (or even just stage the files), none of the guards work, and it's as if someone just added --no-verify to a command line Git declaration to force the commit/push despite failing hooks/guards.
Not sure what I need to do to get husky and lint-staged to work appropriately for any method of staging files, making commits, branch naming, etc. etc.
Does anyone know what I'm doing wrong, or can point me somewhere that might explain what I'm doing wrong? Thanks in advance!

#discordjs/voice can't find encryption package with pnpm

When I try to play audio with #discordjs/voice I just get an error:
ERROR file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/#discordjs+voice#0.13.0_#discordjs+opus#0.9.0/node_modules/#discordjs/voice/src/util/Secretbox.ts:51
throw new Error(
^
ERROR Error: Cannot play audio as no valid encryption package is installed. 20:03:27
- Install sodium, libsodium-wrappers, or tweetnacl.
- Use the generateDependencyReport() function for more information.
at Object.fallbackError (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/#discordjs+voice#0.13.0_#discordjs+opus#0.9.0/node_modules/#discordjs/voice/src/util/Secretbox.ts:51:8)
at Networking.encryptOpusPacket (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/#discordjs+voice#0.13.0_#discordjs+opus#0.9.0/node_modules/#discordjs/voice/src/networking/Networking.ts:585:23)
at Networking.createAudioPacket (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/#discordjs+voice#0.13.0_#discordjs+opus#0.9.0/node_modules/#discordjs/voice/src/networking/Networking.ts:568:47)
at Networking.prepareAudioPacket (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/#discordjs+voice#0.13.0_#discordjs+opus#0.9.0/node_modules/#discordjs/voice/src/networking/Networking.ts:490:31)
at VoiceConnection.prepareAudioPacket (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/#discordjs+voice#0.13.0_#discordjs+opus#0.9.0/node_modules/#discordjs/voice/src/VoiceConnection.ts:520:27)
at AudioPlayer._preparePacket (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/#discordjs+voice#0.13.0_#discordjs+opus#0.9.0/node_modules/#discordjs/voice/src/audio/AudioPlayer.ts:640:15)
at AudioPlayer._stepPrepare (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/#discordjs+voice#0.13.0_#discordjs+opus#0.9.0/node_modules/#discordjs/voice/src/audio/AudioPlayer.ts:604:10)
at prepareNextAudioFrame (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/#discordjs+voice#0.13.0_#discordjs+opus#0.9.0/node_modules/#discordjs/voice/src/DataStore.ts:146:13)
at audioCycleStep (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/#discordjs+voice#0.13.0_#discordjs+opus#0.9.0/node_modules/#discordjs/voice/src/DataStore.ts:127:2)
at Timeout._onTimeout (file:///C:/Users/[username]/Desktop/code/[project name]/node_modules/.pnpm/#discordjs+voice#0.13.0_#discordjs+opus#0.9.0/node_modules/#discordjs/voice/src/DataStore.ts:139:42)
Here's the output of generateDependencyReport():
-------------------------------------------------- 20:11:50
Core Dependencies
- #discordjs/voice: 0.13.0
- prism-media: not found
Opus Libraries
- #discordjs/opus: not found
- opusscript: not found
Encryption Libraries
- sodium-native: not found
- sodium: not found
- libsodium-wrappers: not found
- tweetnacl: not found
FFmpeg
- version: 2021-09-08-git-5e7e2e5031-full_build-www.gyan.dev
- libopus: yes
--------------------------------------------------
These are my dependencies:
"dependencies": {
"#discordjs/opus": "^0.9.0",
"#discordjs/voice": "^0.13.0",
"consola": "^2.15.3",
"discord.js": "^14.6.0",
"libsodium-wrappers": "^0.7.10",
"sodium-native": "^3.4.1",
"tweetnacl": "^1.0.3"
},
As you can see I've clearly installed an encryption package, but it's not being detected by #discordjs/voice.
I believe it's because I am using pnpm, as it's node_modules format is different compared to normal npm.
Does anyone know how to make #discordjs/voice detect it?
It is a bug with #discordjs/voice if it can't work with symlinked dependencies.
But you can use node-linker=hoisted to install a hoisted node_modules without using symlinks. Put this setting to a .npmrc file in the root of you project, remove node_modules and run pnpm install.

SpawnSync doesn't work when using electron-builder

I am writing an react-electron application and I noticed that when I used electron-builder to build it the binary was stuck when calling "spawn".
With "yarn start" the application can be executed without problems. Only with electron-builder it gets stuck.
Can you help ?
Thanks,
Update
It seems that the C++ binary included as part of the program can't be executed within electron. If I give the hardcoded full path to the binary it works but if I give the path from __dirname I get an error
const GetLocalPath = () => {
const path = __dirname + "/../cpp_program/"
return {
helloWorld: path+ "helloWorld",
helloWorldRepeat: path+ "helloWorldRepeat"
}
}
export function helloWorld(){
// let dir = "/Users/Rick/projects/lala/github/tutorial/electron-tutorial-app/cpp_program";
let comm = GetLocalPath().helloWorld;
The error message
internal/child_process.js:403 Uncaught (in promise) Error: spawn ENOTDIR
at ChildProcess.spawn (internal/child_process.js:403)
at Object.spawn (child_process.js:562)
at helloWorldRepeat (/Users/ricky/proje…ar/build/Lib.js:113)
at Object.<anonymous> (/Users/ricky/proje…sar/build/Lib.js:49)
at Generator.next (<anonymous>)
at /Users/ricky/proje…asar/build/Lib.js:9
at new Promise (<anonymous>)
at __awaiter (/Users/ricky/proje…asar/build/Lib.js:5)
at Object.handleInitialize (/Users/ricky/proje…sar/build/Lib.js:35)
at TestStateMachine.transition (/Users/ricky/proje…tStateMachine.js:56)
This is pretty odd because it works just fine with "yarn start", which is "tsc && electron"
package.json is shown below
"scripts": {
"start": "tsc && electron ."
},
"build": {
"appId": "com.example.myapp",
"productName": "MyApp",
"files": [
"build/**/*",
"public/**/*",
"src/images/**/*"
]
},
Update ver 2
Per Alexander's suggestion I have included
"asar": false
inside package.json
When I excute it I get a different error
Uncaught Error: spawn /Users/Rick/projects/lala/github/tutorial/electron-tutorial-app/dist/mac/MyApp.app/Contents/Resources/app/build/../cpp_program/helloWorldRepeat ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269)
at onErrorNT (internal/child_process.js:465)
at processTicksAndRejections (internal/process/task_queues.js:80)
errnoException # internal/errors.js:510
ChildProcess._handle.onexit # internal/child_process.js:269
onErrorNT # internal/child_process.js:465
processTicksAndRejections # internal/process/task_queues.js:80
Now the error is that there is no "helloWorldRepeat" file inside /Users/Rick/projects/lala/github/tutorial/electron-tutorial-app/dist/mac/MyApp.app/Contents/Resources/app/build/../cpp_program/.
The binary is in fact located at
/Users/Rick/projects/lala/github/tutorial/electron-tutorial-app/build/../cpp_program/helloWorldRepeat
Do I have to manually create this folder and paste the binary files ?
By default, Electron Builder compiles your application and packs all resources into one large archive file (think of it as a ZIP file) which can be read just fine because Electron brings support for this format known as "ASAR".
When running the built program, the code will be read from the archive. This means that __dirname will point to a directory inside the archive. The operating system, however, cannot read from the archive. Since you did not actually include the piece of code calling child_process.spawn (), I can only speculate on why you get ENOTDIR, which hints that a given path is not a directory when it was expected to be one, but I assume this is because you point to a path inside the ASAR file.
When relying on external binaries, it is a good idea to keep them outside the ASAR archive and programmatically find the path to them (which is quite complex) or by preventing Electron Builder from compiling your app into an ASAR file. However, you would also have to ask Electron Builder to include the executable in the built version of your app. This can be done by modifying your package.json:
{
...
"build": {
"appId": "com.example.myapp",
"productName": "MyApp",
"files": [
"build/**/*",
"public/**/*",
"src/images/**/*"
],
"extraResources": [
"cpp_program/*"
]
"asar": false
},
}
(Replace "cpp_program/*" by whatever path pattern matches your desired directory, possibly even replacing /* with /**/* if there are subdirectories.)
This way, the directory cpp_program will be copied to your app's resources directory upon build. This path, according to Electron Builder's documentation, is Contents/Resources/ on MacOS. Thus, you will have to modify your path (__dirname + "../" will not work because it will point to Contents/Resources/app, but __dirname + "../../" should; if not, experimenting will lead to the correct path)*. Remember to run Electron Builder every time your C++ executable changes, as the files in the .app folder are not linked to their counterparts outside the built app.
* You can switch between development paths (__dirname + "../") and production paths (__dirname + "../../" or whatever) by checking if __dirname.includes (".app/")

How can I save protractor test results

Is there a way to output protractor test results to a file to be viewed outside of the command line after a test is run, including seeing detailed failures?
I found a nice clean way of saving the test results in a orderly fashion using Jasmine reporter.
How to install and configure Jasmine reporter:
Install Jasmine reporter:
npm install -g jasmine-reporters
Add the following to the protractor-config.js file:
onPrepare: function() {
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmineReporters.JUnitXmlReporter('outputxmldir', true, true));
}
Create the outputxmldir folder (This is where all the test outputs will be placed).
Run protractor and now the results will be exported to an XML file in the outputxmldir folder.
Just the test output is enough?
protractor conf.js > test.log
Cheers.
You can also set the resultJsonOutputFile option in the config file:
export.config = {
(...)
// If set, protractor will save the test output in json format at this path.
// The path is relative to the location of this config.
resultJsonOutputFile:'./result.json',
(...)
}
More details about the config file can be found at:
https://raw.githubusercontent.com/angular/protractor/master/docs/referenceConf.js

Resources