File tree Expand file tree Collapse file tree 3 files changed +11
-15
lines changed Expand file tree Collapse file tree 3 files changed +11
-15
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,7 @@ import path from 'path';
9
9
import { relative } from './util.js' ;
10
10
import { promises as fs } from 'fs' ;
11
11
12
- console . log ( 'import.meta.url:' , import . meta. url )
13
- let pkgPath = relative ( import . meta. url , '../package.json' ) ;
14
- pkgPath = pkgPath . replace ( 'file://' , '' ) ;
12
+ const pkgPath = relative ( import . meta, '..' , 'package.json' ) ;
15
13
const pkgString = ( await fs . readFile ( pkgPath ) ) . toString ( ) ;
16
14
const pkg = JSON . parse ( pkgString ) ;
17
15
const isProd = process . env . NODE_ENV === 'production' ;
Original file line number Diff line number Diff line change @@ -2,18 +2,16 @@ import fs from 'fs';
2
2
import { relative } from './util.js' ;
3
3
var read = fs . readFileSync ;
4
4
var write = fs . writeFileSync ;
5
- let pkgPath = relative ( import . meta. url , '../package.json' ) ;
6
- pkgPath = pkgPath . replace ( 'file://' , '' ) ;
5
+ const pkgPath = relative ( import . meta, '..' , 'package.json' ) ;
7
6
const pkg = JSON . parse ( read ( pkgPath ) . toString ( ) ) ;
8
7
var version = process . env . VERSION || pkg . version ;
9
8
10
- var coverFile = relative ( import . meta. url , '../docs/_coverpage.md' ) ;
11
- coverFile = coverFile . replace ( 'file://' , '' ) ;
12
- var cover = read ( coverFile , 'utf8' ) . toString ( ) ;
9
+ var file = relative ( import . meta, '..' , 'docs' , '_coverpage.md' ) ;
10
+ var cover = read ( file , 'utf8' ) . toString ( ) ;
13
11
14
12
console . log ( 'Replace version number in cover page...' ) ;
15
13
cover = cover . replace (
16
14
/ < s m a l l > ( \S + ) ? < \/ s m a l l > / g,
17
15
'<small>' + version + '</small>'
18
16
) ;
19
- write ( coverFile , cover ) ;
17
+ write ( file , cover ) ;
Original file line number Diff line number Diff line change 1
- /**
2
- * Get an absolute path given a relative path ` from` relative to `to`.
3
- * @param { string } from
4
- * @param { string } to
5
- */
6
- export const relative = ( from , to ) => new URL ( to , from ) . href ;
1
+ import url from 'url' ;
2
+ import path from 'path' ;
3
+
4
+ /** Get a new path relative to the current module (pass import.meta). */
5
+ export const relative = ( meta , ... to ) =>
6
+ path . resolve ( path . dirname ( url . fileURLToPath ( meta . url ) ) , ... to ) ;
You can’t perform that action at this time.
0 commit comments