File tree Expand file tree Collapse file tree 6 files changed +83
-0
lines changed
packages/helper-grammar-regex-collection Expand file tree Collapse file tree 6 files changed +83
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { DOCKER_FROM } from '../../../packages/helper-grammar-regex-collection/index.js' ;
2
+ import insertLink from '../../insert-link' ;
3
+
4
+ export default class Docker {
5
+
6
+ getPattern ( ) {
7
+ return [ 'Dockerfile' ] ;
8
+ }
9
+
10
+ parseBlob ( blob ) {
11
+ insertLink ( blob . el , DOCKER_FROM , {
12
+ resolver : 'dockerImage' ,
13
+ image : '$1' ,
14
+ } ) ;
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ export default function ( { image } ) {
2
+ let isOffical = true ;
3
+ const imageName = image . split ( ':' ) [ 0 ] ;
4
+
5
+ if ( image . includes ( '/' ) ) {
6
+ isOffical = false ;
7
+ }
8
+
9
+ return [
10
+ `https://hub.docker.com/${ isOffical ? '_' : 'r' } /${ imageName } ` ,
11
+ ] ;
12
+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import gitUrl from './git-url.js';
5
5
import githubShorthand from './github-shorthand.js' ;
6
6
import javascriptUniversal from './javascript-universal.js' ;
7
7
import rubyUniversal from './ruby-universal.js' ;
8
+ import dockerImage from './docker-image.js' ;
8
9
9
10
export {
10
11
liveResolverQuery ,
@@ -14,4 +15,5 @@ export {
14
15
gitUrl ,
15
16
githubShorthand ,
16
17
rubyUniversal ,
18
+ dockerImage ,
17
19
} ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ const GEM = /gem (['"][^'"\s]+['"])/g;
9
9
// we could just use https://github.com/Homebrew/homebrew-core/
10
10
const HOMEBREW = / (?: d e p e n d s _ o n | c o n f l i c t s _ w i t h ) (?: c a s k : ) ? ( [ ' " ] [ ^ ' " \s ] + [ ' " ] ) / g;
11
11
const TYPESCRIPT_REFERENCE = / \/ { 3 } \s ? < r e f e r e n c e p a t h = ( [ ' " ] [ ^ ' " \s ] + [ ' " ] ) / g;
12
+ const DOCKER_FROM = / F R O M \s ( [ ^ \n ] * ) / g;
12
13
13
14
export {
14
15
REQUIRE ,
@@ -18,4 +19,5 @@ export {
18
19
GEM ,
19
20
HOMEBREW ,
20
21
TYPESCRIPT_REFERENCE ,
22
+ DOCKER_FROM ,
21
23
} ;
Original file line number Diff line number Diff line change @@ -126,6 +126,18 @@ const fixtures = {
126
126
'// <reference path="foo" />' ,
127
127
] ,
128
128
} ,
129
+ DOCKER_FROM : {
130
+ valid : [
131
+ [ 'FROM foo' , [ 'foo' ] ] ,
132
+ [ 'FROM foo:1.2.3' , [ 'foo:1.2.3' ] ] ,
133
+ [ 'FROM foo:1.2.3-alpha' , [ 'foo:1.2.3-alpha' ] ] ,
134
+ [ 'FROM foo/bar' , [ 'foo/bar' ] ] ,
135
+ ] ,
136
+ invalid : [
137
+ 'FROMfoo' ,
138
+ // 'FROM\nfoo',
139
+ ] ,
140
+ } ,
129
141
} ;
130
142
131
143
describe ( 'helper-grammar-regex-collection' , ( ) => {
Original file line number Diff line number Diff line change
1
+ import assert from 'assert' ;
2
+ import dockerImage from '../../lib/resolver/docker-image.js' ;
3
+
4
+ describe ( 'docker-image' , ( ) => {
5
+ it ( 'resolves foo to https://hub.docker.com/_/foo' , ( ) => {
6
+ assert . deepEqual (
7
+ dockerImage ( { image : 'foo' } ) ,
8
+ [ 'https://hub.docker.com/_/foo' ]
9
+ ) ;
10
+ } ) ;
11
+
12
+ it ( 'resolves foo:1.2.3 to https://hub.docker.com/_/foo' , ( ) => {
13
+ assert . deepEqual (
14
+ dockerImage ( { image : 'foo:1.2.3' } ) ,
15
+ [ 'https://hub.docker.com/_/foo' ]
16
+ ) ;
17
+ } ) ;
18
+
19
+ it ( 'resolves foo:1.2.3-alpha to https://hub.docker.com/_/foo' , ( ) => {
20
+ assert . deepEqual (
21
+ dockerImage ( { image : 'foo:1.2.3-alpha' } ) ,
22
+ [ 'https://hub.docker.com/_/foo' ]
23
+ ) ;
24
+ } ) ;
25
+
26
+ it ( 'resolves foo/bar to https://hub.docker.com/r/foo/bar' , ( ) => {
27
+ assert . deepEqual (
28
+ dockerImage ( { image : 'foo/bar' } ) ,
29
+ [ 'https://hub.docker.com/r/foo/bar' ]
30
+ ) ;
31
+ } ) ;
32
+
33
+ it ( 'resolves foo/bar:1.2.3 to https://hub.docker.com/r/foo/bar' , ( ) => {
34
+ assert . deepEqual (
35
+ dockerImage ( { image : 'foo/bar:1.2.3' } ) ,
36
+ [ 'https://hub.docker.com/r/foo/bar' ]
37
+ ) ;
38
+ } ) ;
39
+ } ) ;
You can’t perform that action at this time.
0 commit comments