Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

magic-comments

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magic-comments - npm Package Compare versions

Comparing version 2.1.11 to 2.1.12

16

package.json
{
"name": "magic-comments",
"version": "2.1.11",
"version": "2.1.12",
"description": "Node.js tool for adding Webpack magic comments at build time.",

@@ -29,3 +29,3 @@ "type": "module",

"lint": "eslint . src __tests__ --ext .js,.ts",
"lint:fix": "npm run lint -- --fix",
"prettier": "prettier ./src ./__tests__ -w",
"test": "BABEL_ENV=test jest",

@@ -42,3 +42,3 @@ "prepack": "npm run build"

"@jest/globals": "^29.6.1",
"@knighted/duel": "^1.0.5",
"@knighted/duel": "^1.0.6",
"@types/micromatch": "^4.0.2",

@@ -48,10 +48,14 @@ "@typescript-eslint/eslint-plugin": "^5.60.1",

"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-prettier": "^4.2.0",
"jest": "^29.6.1",
"prettier": "^2.8.8",
"prettier": "^3.2.4",
"ts-jest-resolver": "^2.0.1",
"typescript": "5.0.4"
},
"prettier": {
"printWidth": 90,
"semi": false,
"singleQuote": true,
"trailingComma": "none"
},
"repository": {

@@ -58,0 +62,0 @@ "type": "git",

@@ -39,13 +39,17 @@ # ✨ [`magic-comments`](https://www.npmjs.com/package/magic-comments)

```js
import { resolve } from 'node:path'
import { readFileSync } from 'node:fs'
import { parse } from 'acorn' // Or another parser
import { getMagicComment } from 'magic-comments'
import { traverseForImportSpecifier } from './utils.js'
const modulePath = resolve(cwd, './src/file.js')
const code = fs.readFileSync(modulePath)
const filename = resolve(cwd, './src/file.js')
const code = readFileSync(filename)
const ast = parse(code)
const dynamicImports = traverseForImportSpecifiers(ast)
dynamicImports.forEach(({ importPath }) => {
dynamicImports.forEach(({ specifier }) => {
const magicComment = getMagicComment({
modulePath,
importPath,
modulePath: filename,
importPath: specifier,
// The options are names of webpack magic comments

@@ -55,3 +59,3 @@ options: {

webpackFetchPriority: (modulePath, importPath) => {
if (importPath.endsWith('module.js')) {
if (importPath.endsWith('important.js')) {
return 'high'

@@ -62,4 +66,5 @@ }

})
// /* webpackChunkName: "folder-module", webpackFetchPriority: "high" */
console.log(magicComment)
// /* webpackChunkName: "module-important", webpackFetchPriority: "high" */
})

@@ -66,0 +71,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc