Skip to content

Commit 0f1fb24

Browse files
committed
v0.1.5 - trying to fix (node:2013) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
✅ Execute properly in Azure DevOps (CommonJS format) ✅ Display proper marketplace overview (README content) ✅ Have a clean package (no unnecessary build artifacts)
1 parent 1094471 commit 0f1fb24

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

component-detection-github-submission-task/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import './sourcemap-register.cjs';import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";
1+
require('./sourcemap-register.cjs');const { createRequire: __WEBPACK_EXTERNAL_createRequire } = require("module");
22
/******/ var __webpack_modules__ = ({
33

44
/***/ 4914:

component-detection-github-submission-task/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"version": {
1010
"Major": 0,
1111
"Minor": 1,
12-
"Patch": 4
12+
"Patch": 5
1313
},
1414
"instanceNameFormat": "Component Detection $(filePath)",
1515
"groups": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"prepare": "ncc build index.ts -o dist --source-map --license licenses.txt",
1010
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
1111
"all": "npm run lint && npm run prepare && npm run test",
12-
"ado:build": "ncc build ado-index.ts -o ado-dist --source-map --license licenses.txt --target es2020 && node -e \"require('fs').copyFileSync('ado-dist/index.js', 'component-detection-github-submission-task/index.js')\"",
12+
"ado:build": "ncc build ado-index.ts -o ado-dist --source-map --license licenses.txt --target es2020 && node scripts/convert-to-cjs.cjs",
1313
"ado:package": "tfx extension create --manifest-globs vss-extension.json",
1414
"ado:all": "npm run ado:build && npm run ado:package"
1515
},

scripts/convert-to-cjs.cjs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const inputFile = path.join(__dirname, '..', 'ado-dist', 'index.js');
5+
const outputFile = path.join(__dirname, '..', 'component-detection-github-submission-task', 'index.js');
6+
7+
// Read the ES module output from ncc
8+
let content = fs.readFileSync(inputFile, 'utf8');
9+
10+
// Convert ES module imports/exports to CommonJS
11+
// Replace import statements at the beginning
12+
content = content.replace(
13+
/^import\s+(['"].*?['"])\s*;/gm,
14+
'require($1);'
15+
);
16+
17+
// Replace import with destructuring
18+
content = content.replace(
19+
/^import\s*{\s*([^}]+)\s*}\s*from\s*(['"].*?['"])\s*;/gm,
20+
'const { $1 } = require($2);'
21+
);
22+
23+
// Replace default imports
24+
content = content.replace(
25+
/^import\s+(\w+)\s+from\s*(['"].*?['"])\s*;/gm,
26+
'const $1 = require($2);'
27+
);
28+
29+
// Replace createRequire import (this is specific to the ncc output)
30+
content = content.replace(
31+
/import\s*{\s*createRequire\s+as\s+__WEBPACK_EXTERNAL_createRequire\s*}\s*from\s*['"]module['"];/g,
32+
'const { createRequire: __WEBPACK_EXTERNAL_createRequire } = require("module");'
33+
);
34+
35+
// Replace any remaining import statements
36+
content = content.replace(
37+
/^import\s+(.*?)\s*;/gm,
38+
'require($1);'
39+
);
40+
41+
// Write the converted content
42+
fs.writeFileSync(outputFile, content, 'utf8');
43+
44+
console.log(`Converted ES module to CommonJS: ${outputFile}`);

vss-extension.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifestVersion": 1,
33
"id": "component-detection-github-submission-task",
44
"name": "Component Detection for GitHub Dependency Submission",
5-
"version": "0.1.4",
5+
"version": "0.1.5",
66
"publisher": "AdvancedSecurityOSS",
77
"description": "Upload information about your dependencies to the GitHub dependency graph using Microsoft's component detection library",
88
"public": false,
@@ -25,10 +25,6 @@
2525
"default": "images/extension-icon.png"
2626
},
2727
"files": [
28-
{
29-
"path": "ado-dist",
30-
"addressable": true
31-
},
3228
{
3329
"path": "component-detection-github-submission-task"
3430
},
@@ -39,6 +35,11 @@
3935
"path": "ADO-README.md"
4036
}
4137
],
38+
"content": {
39+
"details": {
40+
"path": "ADO-README.md"
41+
}
42+
},
4243
"contributions": [
4344
{
4445
"id": "component-detection-github-submission-task",

0 commit comments

Comments
 (0)