Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An update that includes working code for all tests #340

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ browserify-test/script.js
browserify-test/script.js.map
header-test/script.js
header-test/script.js.map
webpack-test/dist/compiled.js
webpack-test/compiled.js
vite-test/index.html
vite-test/assets/
.temp.js

12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
language: node_js
node_js:
- 10
- 9
- '8'
- '7'
- '6'
- '4'
- '0.12'
- '0.10'
- '22'
- '20'
- '18'

1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2014 Evan Wallace
Copyright (c) 2024 Wojciech Banaś

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@ This repo contains both automated tests for node and manual tests for the browse
* Launch the HTTP server (`npm run serve-tests`) and visit
* http://127.0.0.1:1336/amd-test
* http://127.0.0.1:1336/browser-test
* http://127.0.0.1:1336/browserify-test - **Currently not working** due to a bug with browserify (see [pull request #66](https://github.com/evanw/node-source-map-support/pull/66) for details).
* For `header-test`, run `server.js` inside that directory and visit http://127.0.0.1:1337/
* http://127.0.0.1:1336/browserify-test - It works when we use for browserify the coffeeify transform module. The description of the problem when not using this module is: [pull request #66](https://github.com/evanw/node-source-map-support/pull/66).
* http://127.0.0.1:1336/vite-test/
* http://127.0.0.1:1336/webpack-test/
* For `header-test`, run `npm run serve-header-tests` and visit http://127.0.0.1:1337/

## License

Expand Down
105 changes: 1 addition & 104 deletions browser-source-map-support.js

Large diffs are not rendered by default.

59 changes: 17 additions & 42 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ const path = require('node:path');
const child_process = require('node:child_process');
const https = require('node:https');
const { text } = require('node:stream/consumers');
var UglifyJS = require("uglify-js");

const browserify = path.resolve(path.join('node_modules', '.bin', 'browserify'));
const webpack = path.resolve(path.join('node_modules', '.bin', 'webpack'));
const coffee = path.resolve(path.join('node_modules', '.bin', 'coffee'));
const vite = path.resolve(path.join('node_modules', '.bin', 'vite'));

function run(command, callback) {
console.log(command);
Expand All @@ -35,44 +37,13 @@ run(browserify + ' .temp.js', (error, stdout) => {
'return sourceMapSupport});',
].join('\n');

// Use the online Google Closure Compiler service for minification
const body = new URLSearchParams({
compilation_level: 'SIMPLE_OPTIMIZATIONS',
output_info: 'compiled_code',
output_format: 'text',
js_code: code
});

const buffer = new TextEncoder().encode(body.toString())

console.log('making request to google closure compiler');

const request = https.request({
method: 'POST',
host: 'closure-compiler.appspot.com',
path: '/compile',
headers: {
'content-length': buffer.byteLength,
'content-type': 'application/x-www-form-urlencoded'
},
});

request.once('response', response => {
text(response).then(stdout => {
fs.unlinkSync('.temp.js');

if (response.statusCode !== 200) {
console.error(stdout);
throw new Error('failed to post to closure compiler');
}

const code = header + '\n' + stdout;
fs.writeFileSync('browser-source-map-support.js', code);
fs.writeFileSync('amd-test/browser-source-map-support.js', code);
});
});

request.end(buffer);
var result = UglifyJS.minify(code);

if (result.error !== undefined) throw result.error;

const codeMin = header + '\n' + result.code;
fs.writeFileSync('browser-source-map-support.js', codeMin);
fs.writeFileSync('amd-test/browser-source-map-support.js', codeMin);
});

// Build the AMD test
Expand All @@ -81,13 +52,11 @@ run(coffee + ' --map --compile amd-test/script.coffee', error => {
});

// Build the browserify test
run(coffee + ' --map --compile browserify-test/script.coffee', error => {
run(browserify + ' -t coffeeify --debug browserify-test/script.coffee > browserify-test/compiled.js', error => {
if (error) throw error;
run(browserify + ' --debug browserify-test/script.js > browserify-test/compiled.js', error => {
if (error) throw error;
})
});


// Build the browser test
run(coffee + ' --map --compile browser-test/script.coffee', error => {
if (error) throw error;
Expand All @@ -104,3 +73,9 @@ run(coffee + ' --map --compile header-test/script.coffee', error => {
child_process.exec(webpack, {cwd: 'webpack-test'}, error => {
if (error) throw error;
});

// Build the vite test
child_process.exec(vite + ' build --outDir ../', {cwd: 'vite-test/src'}, error => {
if (error) throw error;
});

2 changes: 1 addition & 1 deletion header-test/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p>
Make sure to run build.js, then run server.js and visit <a href="http://localhost:1337/">http://localhost:1337/</a>.
Make sure to run build.js, then run "npm run serve-header-tests" and visit <a href="http://localhost:1337/">http://localhost:1337/</a>.
This test should say either "Test failed" or "Test passed":
</p>
<script src="browser-source-map-support.js"></script>
Expand Down
6 changes: 5 additions & 1 deletion header-test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ http.createServer(function(req, res) {

case '/script-source-map.map': {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(fs.readFileSync('script.map', 'utf8'));
try {
res.end(fs.readFileSync('script.map', 'utf8'));
} catch(err) {
res.end(fs.readFileSync('script.js.map', 'utf8'));
}
break;
}

Expand Down
Loading