File: mjs2cjs

package info (click to toggle)
pkg-js-tools 0.16.0
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,992 kB
  • sloc: perl: 4,975; sh: 840; makefile: 36; javascript: 22
file content (66 lines) | stat: -rwxr-xr-x 1,196 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash

set -e

DIR=`mktemp -d`
cd $DIR

cat > package.json << EOF
{
  "name": "mjs2cjs-test",
  "version": "0.0.1",
  "type": "module",
  "exports": {
     "require": "dist/index.cjs"
  }
}
EOF

cat > index.mjs << EOF
import chalk from 'chalk';
import sliceAnsi from 'slice-ansi';

const string = 'The quick brown ' + chalk.red('fox jumped over ') +
	'the lazy ' + chalk.green('dog and then ran away with the unicorn.');

console.log(sliceAnsi(string, 20, 30));
EOF
mjs2cjs index.mjs
cd /
RES=`node $DIR/dist/index.cjs`
if [ "$RES" != "jumped ove" ]; then
	echo "Result isn't 'jumped ove' but:" >&2
	echo $RES >&2
	exit 1
fi

rm -rf $DIR/dist
cd $DIR
cat > package.json << EOF
{
  "name": "mjs2cjs-test",
  "version": "0.0.1",
  "type": "module",
  "exports": "./index.mjs"
}
EOF
pkgjs-ln chalk
pkgjs-ln slice-ansi
pkgjs-ln @rollup/plugin-node-resolve
mjs2cjs -a index.mjs
cd /
RES=`pkgjs-pjson $DIR exports require`
if [ "$RES" != "./dhnodejsBundle.cjs" ]; then
	echo "package.json is wrong:" >&2
	cat $DIR/package.json >&2
	exit 1
fi

RES=`node $DIR/dhnodejsBundle.cjs`
if [ "$RES" != "jumped ove" ]; then
	echo "Result isn't 'jumped ove' but:" >&2
	echo $RES >&2
	exit 1
fi

rm -rf $DIR